Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question on Id Generation Strategies

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

Q1) When we say for the IdGenerator as,

@TableGenerator(name="Emp_Gen")
@Id @GeneratedValue(generator="GEN_VAL")
private ind id;

Which table would the persistence provider refer to generate the Id values??as here we did not specify any table details.

Q2) As far as I understood the 4 strategies, when I say AUTO, the Persistence Provider may either choose IDENTITY or SEQUENCE or TABLE generator for the primary key generation. Am I right in this sense?
 
Raf Szczypiorski
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. The table name, if not specified (as well as some other attributes) defaults to a provider specific setting.
2. That's right ;-)

Raf
 
Niranjan Deshpande
Ranch Hand
Posts: 1277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jothi Shankar Kumar wrote:Guys,

Q1) When we say for the IdGenerator as,

@TableGenerator(name="Emp_Gen")
@Id @GeneratedValue(generator="GEN_VAL")
private ind id;

Which table would the persistence provider refer to generate the Id values??as here we did not specify any table details.

Q2) As far as I understood the 4 strategies, when I say AUTO, the Persistence Provider may either choose IDENTITY or SEQUENCE or TABLE generator for the primary key generation. Am I right in this sense?


Regarding Q1- the values of generator and name do not match. Will this give a error in first place? So should not this be:

@TableGenerator(name="Emp_Gen")
@Id @GeneratedValue(generator="Emp_Gen") //and not GEN_VAL
private ind id;

with the table attribute value defaulting to a provider specific setting.

Please correct me if I am missing something.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic