• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JPA and Generated Key

 
Timothy Sam
Ranch Hand
Posts: 751
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys! Is there a functionality in JPA that allows a user to get the generated key like what you could do in plain old JDBC? Thanks!
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The @GeneratedValue annotation which supports four different strategies to generate ids. (e.g. using a sequence)
 
Timothy Sam
Ranch Hand
Posts: 751
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks! It seems that the generated key cannot be used without commiting a transaction first? I'm trying to insert a record then get the generated key and then update the record. But the record it seems is not being saved. I could make two different transactions and commit each but that would only rollback 1 transaction.


[ May 23, 2007: Message edited by: Timothy Sam ]
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, the transaction must be committed before you can access the generated id.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic