aspose file tools
The moose likes Object Relational Mapping and the fly likes Hibernate versioning and natural ids Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Reply Bookmark "Hibernate versioning and natural ids" Watch "Hibernate versioning and natural ids" New topic
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.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Hibernate versioning and natural ids
 
Similar Threads
mapping question (hashmap and subclasses)
Concurrent updates does not throw any exception
Composite Unique Key problem in Hibernate.
WA #1.....word association
Replacing *.hbm.xml files with @Annotations.