• Post Reply Bookmark Topic Watch Topic
  • New Topic

Difference between id generators

 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys,

What is the prime difference between a @TableGenerator and a @SequenceGenerator and what they ultimately do is to generate a primary key for which the AUTO would do the same thing. Can you please help me differentiate the importance.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you read about both annotations, you'll see that @TableGenerator uses a table to hold primary keys. The next primary key value will be taken from that table and incremented. @SequenceGenerator uses a database sequence (like Oracle sequences) to generate primary keys. Setting the generation type (GenerationType) to AUTO will let the persistence provider choose for you which type to use. You can implicitly tell it which type to use via either IDENTITY, TABLE or SEQUENCE. If you do so, you have to check that your persistence provider supports the GenerationType.
 
Gravity is a harsh mistress. But this tiny ad is pretty easy to deal with:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!