aspose file tools*
The moose likes Java in General and the fly likes Java Objects and Database Records Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Java Objects and Database Records" Watch "Java Objects and Database Records" New topic
Author

Java Objects and Database Records

David Garratt
Ranch Hand

Joined: Aug 08, 2003
Posts: 198

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.

Dave
Preetham Chandrasekhar
Ranch Hand

Joined: Nov 05, 2003
Posts: 98
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
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
I recently asked a similar question recently because I was working on a Swing application that needed to connect to a database. Perhaps the suggestion made there will help.

Layne
[ July 14, 2005: Message edited by: Layne Lund ]

Java API Documentation
The Java Tutorial
Jacquie Barker
author
Ranch Hand

Joined: Dec 20, 2000
Posts: 201
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 (jacquie@objectstart.com) and I'll elaborate.

Regards,

Jacquie


Author of Beginning Java Objects, Beginning C# Objects, and Taming the Technology Tidal Wave
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java Objects and Database Records