-->
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.  [ 1 post ] 
Author Message
 Post subject: @Version not working with not detached objects?
PostPosted: Wed Nov 07, 2007 6:37 am 
Newbie

Joined: Wed Nov 07, 2007 5:52 am
Posts: 1
Hi all,

I am getting an unexpected behaviour when using @Version that is only working with detached objects.

I have two concurrent requests that load the same persistent instance -therefore obtain the same version number-, modify some attributes and try to commit. I would expect the latest to throw an OptimisticLockException. However, both objects get committed unless I perform an evict.

Here is a test that shows it:
Code:
startNewTransaction();
this.setComplete();
Mortgage mortgage1 = basicController.find(Mortgage.class, 1);
mortgage1.setName("John");
mortgage1 = basicController.merge(mortgage1);
endTransaction();
      
startNewTransaction();
this.setComplete();
Mortgage mortgage2 = basicController.find(Mortgage.class, 1);

/*************
* This line is necessary to get an OptimisticLockException   
*************/
//((Session)basicDAO.getEntityManager().getDelegate()).evict(mortgage2);

mortgage2.setName("David");
mortgage2.setVersion(0);
basicController.merge(mortgage2); // OptimisticLockException expected!!
endTransaction();


I was considering reporting this as a bug but wanted to get some feedback before.

Thanks in advance


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.