-->
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.  [ 2 posts ] 
Author Message
 Post subject: how to use version column ?
PostPosted: Wed Nov 05, 2003 8:47 pm 
Newbie

Joined: Wed Nov 05, 2003 8:39 pm
Posts: 1
in the hibernate reference document , I found something about version columen , but how to use it , and which module is the implementation of it.

------------------------------------------------------------------------------------
4.1.7. version (optional)
The <version> element is optional and indicates that the table contains versioned data. This is particularly useful
if you plan to use long transactions (see below).
Code:
<version
column="version_column"
name="propertyName"
type="typename"
/version>


column (optional - defaults to the property name): The name of the column holding the version number.
name: The name of a property of the persistent class.
type (optional - defaults to integer): The type of the version number.

Version numbers may be of type long, integer, short, timestamp or calendar.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 05, 2003 11:52 pm 
Regular
Regular

Joined: Wed Nov 05, 2003 10:57 pm
Posts: 96
You need to add a field (with setter and getter) for the version in you persistent object, and use the version element in the mapping. The version gets incremented everytime the object is updated.

If 2 concurrent users update the same persistent object (e.g version=5), the first user increments the version (version=6), and the second gets a StaleObjectStateException when trying to commit the change (his object has version=5 while the corresponding object in the database has a version of 6). This exception can be used to suggest the reloading of the persistent object.

mota


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.