| Author |
Hibernate versioning and natural ids
|
Cristian Vrabie
Ranch Hand
Joined: Jul 09, 2008
Posts: 71
|
|
Hey there, just noticed that in the hibernate mapping you can't include a version into a natural id? Any idea why? It seems to me that a name together with a version number form a good natural id.
|
 |
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
|
|
Hey there, just noticed that in the hibernate mapping you can't include a version into a natural id? Any idea why? It seems to me that a name together with a version number form a good natural id.
A natural ID would would be supported by the "assigned" id generation strategy which will support whatever you like. What makes you think you can't include a version?
|
JavaRanch FAQ HowToAskQuestionsOnJavaRanch
|
 |
Cristian Vrabie
Ranch Hand
Joined: Jul 09, 2008
Posts: 71
|
|
Originally posted by Paul Sturrock: What makes you think you can't include a version?
well, according to the DTD you can't place a version element in the natural id element:
|
 |
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
|
|
The version element is for Hibernate's optimistic locking strategy, so you can't use that element. Because of that it only has meaning when you update an entity. If you create a primary key that includes a version column this means you can effectively never update your entities. If you change an row's identifier you are strictly deleting the row and creating a new one. And Hibernate is strict in its application of RDBMS principles. But you could write your own verioning implementation that does this work for you.
|
 |
Cristian Vrabie
Ranch Hand
Joined: Jul 09, 2008
Posts: 71
|
|
|
Ah, got it! I was confuse about the version element.
|
 |
 |
|
|
subject: Hibernate versioning and natural ids
|
|
|