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?
|