-->
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.  [ 5 posts ] 
Author Message
 Post subject: Using version in Hibernate
PostPosted: Fri Feb 24, 2006 10:12 pm 
Newbie

Joined: Fri Feb 24, 2006 6:16 am
Posts: 4
Hello everybody.
I'm learning Hibernate, and I found something so strange when using version checking in Hibernate.
When I get, load, or select an object from database, although I don't modify it, the session is always marked dirty. So when I commit the transaction, the version of that row is increased.
I think this is an error.
This is my code:
------------------------------------------------------------
Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();

TestDepartment department =
(TestDepartment)session.get(TestDepartment.class, new Long(1));

tx.commit(); //the version of department is increased after this line.
session.close();
------------------------------------------------------------

And this is the hbm.xml file:

<class
name="generated.de.TestDepartment"
table="TEST_DEPARTMENT"
schema="INDEXATION"
dynamic-update="true"
lazy="false">

<id name="departmentId" type="long">
<column name="DEPARTMENT_ID" scale="0" />
<generator class="native" />
</id>

<version
name="version"
column="VERSION"
unsaved-value="null">
</version>

<property name="name" type="string">
<column name="NAME" />
</property>
</class>
Can you tell me why. Did I make any mistakes?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 24, 2006 10:24 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Check that your not doing something wrong in the domain object.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 24, 2006 11:02 pm 
Newbie

Joined: Fri Feb 24, 2006 6:16 am
Posts: 4
Can you explain it more clearly? I'm just a newbie.
Thanks any way.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 25, 2006 7:13 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
If your domain object is coded incorrectly it can result in a dirty status so an update will occur. This is not so uncommon for beginners when they are cut-and-pasting setters/getters but forget to change the field reference. For example, two setters refer to the save private field so when the object is loaded Hibernate sets the fields which internally the POJO is changed when the state is checked. Hope this is clear.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 26, 2006 3:48 pm 
Newbie

Joined: Tue Jan 25, 2005 3:03 am
Posts: 11
Location: Bangalore, India
Hi,

Although I don't know why you are facing this issue, I am sure the hibernate logs would atleast get us started with figuring it out. Can you attach them here ?

_________________
Rgds,
Vikas.

"Quidquid latine dictum sit, altum sonatur".
Whatever is said in Latin, sounds profound


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