views:

78

answers:

2

I'm looking at a database dump file, and I see many records in various tables with their version number set in values other than 0 (even 94 in one case). I understand it has to do with hibernate locking strategy, but my concern is that today is Sunday, and the site has almost no visitors so is: is this normal ? Or is there a known hibernate bug or even some programming malpractice producing this ?

By the way is it safe / recommended to reset these values manually to zero when restoring a database backup ?

+2  A: 

The Hibernate version field is really just a count of how many times that record has been saved (well, minus 1, since the first time it's saved the value is 0). Note that this number isn't actually used as a save count, so the actual value at any time isn't important.

The way it's used is to determine if the row has been saved in between when you read the row and when you try to save the row. If you read the row and the version value is 12, then later you changed the object and tried to save it. The first thing Hibernate does is check to see if the value in the DB for version on that row is still 12. If not, then some other process has saved that row since you read it, and if you save now, you may overwrite some changes made during that previous save.

To answer your question... As long as nothing is "in the middle" of a potential read/store process (like the site is down, or some such), then you can change the version field to whatever number you like. It will increment from there every time that row is stored.

Bill James
+1  A: 

Also, if you don't need it you can turn it off with

static mapping{ version false }

leebutts