Enlightensoft's Blog

Helping in your each step

  • Categories

  • Authors

Hibernate Automatic Dirty Check for Detached Objects

Posted by Pankil Patel on April 18, 2012

To deal with Dirty check for detached objects in Hibernate there are two ways:

1)

.hbm.xml file:

Using <version> tag in .hbm.xml file like below:

In .hbm.xml file: <version name=”version” access=”field” column=”version” type=”long”/>

In respected VO / POJO: private Long version; /* used for optimistic locking */

Annotation:

import javax.persistence.Version;

@Version
private Long version;

 

2) 

.hbm.xml file:

Using <timestamp> tag in .hbm.xml file like below:

In .hbm.xml file: <timestamp name="lastModifyDataTime" column="LAST_MODIFIY_DATE_TIME" access="field">

In respected VO / POJO: private Long lastModifyDataTime;

Annotation:

import javax.persistence.Version;

@Version
private Long lastModifyDataTime;

 

Note: Hibernate ignores the version when getting object and updating fields and then version are in the same session.

 

For more detail on Optimistic lock in Hibernate visit:

http://turgaykivrak.wordpress.com/2009/05/16/72/

AND

http://www.intertech.com/Blog/Post/Versioning-Optimistic-Locking-in-Hibernate.aspx

 

3) Use select-before-update=”true” mapping into your .hbm.xml file:

<class name=”com…….AbcVO”
table=”ABC” select-before-update=”true”>

4) By extending some of its public API:

http://www.brimllc.com/2010/08/hibernate-automatic-dirty-check-for-detached-objects/

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: