-->
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: Version- doesnt throw StaleStateObjectException
PostPosted: Thu Mar 16, 2006 8:22 am 
Newbie

Joined: Fri Jan 13, 2006 1:40 pm
Posts: 11
Hi All,

Our approach is as follows,

1. An entity is retrieved.

2.Hibernate session is closed

3. The entity data is displayed to a web browser.

4. The entity is updated and sent over to the service layer (as a DTO).

To update the entity

1. A new Hibernate session is opened.

2. Entity is retrieved and updated with the data in the DTO. (Please Note that the entire model
object cant be constructed using the DTO as it may contain values of just a few attributes of the model
Object so this retrieval becomes unavoidable)

3. Now we set the optimistic Lock Version with the value which was intially retrieved and carried over to the presentation layer.

But this approach doesnt seem to work.As We dont get any StaleStateObjectException instead
Update happens successfully.

When I examined the Update query,Hibernate doesnt seem to pick the OptimisticLockVersion set by me
but rather picks the one which was there in the DB (i.e The one in that Object before setting it with presentation layer one)


I have included the Junit test case below ,to demonstrate the same behaviour.


Wot is the change that I need to make.?


Thanks
Yesh

Any Help is Valued

Hibernate version:

Hibernate 3.0

Mapping documents:

<hibernate-mapping package="com.csg.charts.model">
<class name="Test" table="TEST">
<id name="testId" type="long" column="TEST_ID">
<generator class="sequence" >
<param name="sequence">TEST_PK_SQ</param>
</generator>
</id>
<version name="concurrencyVersion" column="C_VERSION" type="long"/>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():

public void test_OptimisticLock()
{
Test test= (Test) ht.get(Test.class,new Long(8));
test.setConcurrencyVersion(new Long(1));
ht.saveOrUpdate(test);

ht.flush();
setComplete();

}
Full stack trace of any exception that occurs:

The expected Stack Trace doeesnt Occur

Name and version of the database you are using:

Oracle9i

The generated SQL (show_sql=true):


update CHART set C_VERSION=?, CHART_DEFN_ID=?, ACCOUNT_VERSION_ID=?, inProposal=? where CHART_ID=? and C_VERSION=?

For the above test case,
The C_VERSION in where clause is the one retrieved from DB and not
the '1' which was explicitly set.

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 17, 2006 3:00 am 
Newbie

Joined: Fri Jan 13, 2006 1:40 pm
Posts: 11
Is it a Bug in Hibernate ?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 22, 2006 7:36 am 
Beginner
Beginner

Joined: Tue Oct 07, 2003 4:41 am
Posts: 21
Hi,

I've got the same problem. I'm using more or less the same pattern as you are and I can't seem to get the Update statement to use the Version value I have manually set on the object.

There were no other replies, so I'm posting in the hope you may have figured it out in the mean time.

regards

John


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 22, 2006 8:51 pm 
Beginner
Beginner

Joined: Tue Oct 07, 2003 4:41 am
Posts: 21
Just an update in case it's useful to others.
There was another posting on the same topic.

http://forum.hibernate.org/viewtopic.php?t=955121

I used the proposed solution in the flushDirty of an Interceptor and it worked for me.

regards

John


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 27, 2006 8:52 am 
Newbie

Joined: Fri Jan 13, 2006 1:40 pm
Posts: 11
Thanks


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.