• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java Objects and Database Records

 
David Garratt
Ranch Hand
Posts: 213
Eclipse IDE Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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/
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Jacquie Barker
author
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic