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

Hibernate versioning and natural ids

 
Cristian Vrabie
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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?
 
Cristian Vrabie
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, got it! I was confuse about the version element.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic