-->
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: version and legacy database
PostPosted: Tue Mar 13, 2007 1:18 pm 
Beginner
Beginner

Joined: Thu Dec 23, 2004 5:24 am
Posts: 40
Location: Luxembourg
Hi,

I have a specific case and I'd like to know if a feature exist in Hibernate to make it work:
I want to connect to a legacy database that has an update_date column in each of its tables. I'd like to use optimistic locking with the version attribute mapped to these columns in my hibernate mapping files, but hibernate shouldn't increment the version numbers by itself because the database has triggers to increment these columns automatically when an update is performed on the data. Is there a way to do this ?

Thanks for your help.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 13, 2007 2:54 pm 
Expert
Expert

Joined: Tue Jul 11, 2006 10:21 am
Posts: 457
Location: Columbus, Ohio
Use a <timestamp> element to describe that column in your mapping files. It will be used for optimistic locking. Pertinent link: http://www.hibernate.org/hib_docs/v3/re ... -timestamp

Of course, it is equivalent to <version type="timestamp"> , but I think the <timestamp> element is cleaner looking. Up to you.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 14, 2007 4:07 am 
Beginner
Beginner

Joined: Thu Dec 23, 2004 5:24 am
Posts: 40
Location: Luxembourg
Ananasi wrote:
Of course, it is equivalent to <version type="timestamp"> , but I think the <timestamp> element is cleaner looking. Up to you.

Not only it is cleaner looking, but also I can use it with the attribute generated set to "always". That way Hibernate won't increment the value on insert or update and will let the triggers in the database do so. It looks like this solves my problem.

Thank you very much for your help.


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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.