This week's book giveaway is in the OCAJP forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line! See this thread for details.
Can anyone suggest suitable reading material to guide me in designing class's which specifically map to database tables and provide a "standard" approach to record manipulation. For example I find myself unsure as to the best practice for creating a new record in a table. Do I create a new instance of an object, passing the primary key to the constructor and allow the constructor to create a matching record OR do I create new object, set various fields and then call a method call .Create or .Insert
I'm happy with the mechanics of JDBC - I just need some advice as to best practice if indeed there is an agreed best way of doing this.
Hi, Since you are using java objects and would like to create records in the database, I prefer using Object-Relational mapping tools like Hibernate. This is a suggestion because it makes things a lot easier where primary keys are automatically generated (object ids). However it is really slow when compared to jdbc. http://www.hibernate.org/
"In theory, there is no difference between theory and practice. But, in practice, there is."<br /> - Jan L.A. van de Snepscheut
When designing an application with persistent storage, it's important to strive for model - data layer separation. That is, rather than embedding JDBC code into the constructor for a model object, e.g.
it's better to have a separate class(es) that provide database access and "serve" Person objects to the application:
I have an entire example of this in Chapter 15 of B.J.O. ... drop me an email (firstname.lastname@example.org) and I'll elaborate.