These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: managed version
PostPosted: Thu Aug 24, 2006 10:52 am 
Newbie

Joined: Thu Aug 24, 2006 10:35 am
Posts: 2
hi,
We are tring to use managed version via hibernate 3.0 with sql server 2005. For now , the timestamp is used. As Hibernate in action said,
"Managed versioning relies on either a version number that is incremented or a
timestamp that is updated to the current time, every time an object is modified." (P169)
our question is that how the timestamp will be updated every time an object is modified ? Done by hibernate or by database? Indeed, we know that mysql can update the timestamp for us, but sql server seems not. I am not very sure about it so hope getting a help ,especially in the sql server 2005 scenario. If the timestamp can not be updated automatically by sql server or hibernate, does we need to use trigger to do that?


TIA


OrNot


Top
 Profile  
 
 Post subject: One Way to do it
PostPosted: Thu Aug 24, 2006 12:40 pm 
Newbie

Joined: Thu Aug 24, 2006 11:58 am
Posts: 5
Here is how I do it. Every object that I want to version (to prevent writing stale data) has an integer version property. A corresponding integer database row is also created. Hibernate takes care of everything else. If anyone tries to update an object with a version number lower than the current one in the db for that row, Hibernate throw an error.

Code:
   
<version
            name="version"
            type="int"
            column="version"
            access="property"
            unsaved-value="negative"
        />


If you really needed to know the time when data was modified, then that is a different kettle of fish.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 24, 2006 12:51 pm 
Senior
Senior

Joined: Wed Aug 17, 2005 12:56 pm
Posts: 136
Location: Erie, PA (USA)
You can do basically the same with a date/time:
Code:
<version column="last_modified" name="lastModified" type="timestamp" />


I believe that you are not going to want a SQLServer timestamp -- just a date/time -- timestamp is managed by SQLServer.

Curtis ...

_________________
---- Don't forget to rate! ----


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.