• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Nakata kokuyo
Ranch Hand
Posts: 472
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Nakata kokuyo
Ranch Hand
Posts: 472
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark, i assume auto generate means by increment ?
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 472
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cool Mark, thanks for the guidance
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic