-->
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: Versioning (optimistic locking)
PostPosted: Tue Apr 24, 2007 4:59 am 
Beginner
Beginner

Joined: Sun Aug 13, 2006 8:40 am
Posts: 28
Hi!

I am having a strange problem when adding a version to a domain object operated by Hibernate.

In other objects (where this is successful), the only modification which is done is editing the mapping document, but with this particular object this does not work. I am expecting that hibernate throws an exception if the version of the updated object does not comply, but this is not done...

Hibernate is updating (incrementing) the version property in the database, but this is obvious not used when updating the object.

As I mentioned I have objects which is using this feature successfully, but whit this object, this want comply. The only difference that I can think of in the environment is that this object is being updated in an EJB which has transactions enabled, where the other EJBs which is doing this correctly has transactions disabled. I would not think that this should affect the behavior of hibernate. For the cause of testing this we disabled the transactions but there was no change.

Is there anything besides the mapping document that needs to be configured to enable optimistic locking when updating of objects? Does anyone have an idea of what could be causing this problem? Please help!

Hibernate version:
Hibernate3 3.0.5

Mapping documents:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping>
<!--
    Created by the Middlegen Hibernate plugin 2.1

    http://boss.bekk.no/boss/middlegen/
    http://www.hibernate.org/
-->

<class
    name="some.Object"
    table="T_OBJECT"
>
   <meta attribute="implement-equals" inherit="false">true</meta>
<!--
   Merged T_OBJECT.merge into T_OBJECT.hbm.xml
-->
<!-- No ${plugin.mergedir}/T_OBJECT.merge found.
   hibernate
-->

    <id
        name="id"
        type="java.lang.Integer"
        column="ID"
        unsaved-value="0"
    >
        <generator class="identity" />
    </id>
   
   <version
        name="versjon"
        type="java.lang.Integer"
        column="VERSJON"
        unsaved-value="null"
    /> 
...
</class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
Handled by spring-framework v 1.2.8

Full stack trace of any exception that occurs:
n/a

Name and version of the database you are using:
db2 8x

The generated SQL:
Code:
update T_OBJECT set VERSJON=?, ... where ID=? and VERSJON=?"   


Debug level Hibernate log excerpt:
?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 24, 2007 5:31 am 
Beginner
Beginner

Joined: Sun Aug 13, 2006 8:40 am
Posts: 28
The generated select statement before the update:
Quote:
Hibernate: select o0_.ID as O_0_, ... from T_OBJECT o0_ ... where o0_.PROPERTY=?


I am sorry to exclude the name and properties of from the select statement, update statement and mapping file, but I am in no position to reveal internal business logic. I just hope that i did not remove any important text...


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.