Meaningless Drivel is fun!*
The moose likes Object Relational Mapping and the fly likes @GeneratedValue with max value from table Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "@GeneratedValue with max value from table" Watch "@GeneratedValue with max value from table" New topic
Author

@GeneratedValue with max value from table

Jay Abrahm
Ranch Hand

Joined: May 28, 2008
Posts: 183
Is there a way to configure the @Id field to have max value of table + 1.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Why do you want it to do this? Is it not enough to just be assured of a unique value?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Hauke Ingmar Schmidt
Rancher

Joined: Nov 18, 2008
Posts: 433
    
    2
As Paul said, it is normally not needed.

If you want to do so you need to set a different strategy for the generated value. If you use a TABLE strategy (and configure it correctly) an extra table will be created that takes the sequence name and the last assigned value and will set a new id to the next value. Or you can set an id in the PrePersist JPA event. (Or even in a db trigger.)

But unless there are extremely important reasons for the constraint and the decision is made by people who fully understand the implications this manual approach to id generation has, this is a bad idea.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: @GeneratedValue with max value from table