IntelliJ Java IDE
The moose likes Object Relational Mapping and the fly likes is it a must to have id for each mapping file ? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Object Relational Mapping
Reply Bookmark "is it a must to have id for each mapping file ?" Watch "is it a must to have id for each mapping file ?" New topic
Author

is it a must to have id for each mapping file ?

Nakata kokuyo
Ranch Hand

Joined: Apr 13, 2005
Posts: 437
Good day to all,

i'm newbie to hibernate, my question is do we really need to have a generator id for each database table for mapping ?

also, what are the best generator id strategy in hibernate ?

thank you very much for guidance
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 16624

Yes you must have an id to uniquely identify the object to one and exactly one record/row/tuple in the database.

I usually choose auto for the generation type to allow Hibernate to just use the underlying databases generation type, this leaves you code generic enough for switching out databases.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Nakata kokuyo
Ranch Hand

Joined: Apr 13, 2005
Posts: 437
Mark, i assume auto generate means by increment ?
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 16624

Originally posted by Nakata kokuyo:
Mark, i assume auto generate means by increment ?


No, actually in the mapping file it is called "native" in JPA it is called Auto. "increment" works with MySql, but not Oracle which would need "sequence", but if I had "native" then it covers both MySql and Oracle because the dialect will tell which one the vendor natively uses.

Mark
Nakata kokuyo
Ranch Hand

Joined: Apr 13, 2005
Posts: 437
Cool Mark, thanks for the guidance
 
IntelliJ Java IDE
 
subject: is it a must to have id for each mapping file ?
 
Threads others viewed
sequence generator with mysql
Hibernate Mapping problem because no primary key in database
Simple one-to-one relationship with FK.
hybernate doubt
How to update table with autoincrement column in JSF application
IntelliJ Java IDE