persistence@glassfish.java.net

Re: Problems with optimistic concurrency?

From: James Sutherland <jamesssss_at_yahoo.com>
Date: Mon, 16 Jun 2008 06:34:43 -0700 (PDT)

That is odd. Could you please include the full stack trace to the exception.
Also what about Timestamp locking does not work? It should work, as long as
you use a valid timestamp type in the database that stores milliseconds
correctly (what database and type are you using?).

Is the object you are merging new or existing?



Adam Bien wrote:
>
> Hi All,
>
> I'm testing now the optimistic concurrency behavior. All primitive
> datatypes seems to work fine:
>
> @Entity
> public class Entity{
>
> @Version
> private int version;
>
> }
>
> @Entity
> public class Entity{
>
> @Version
> private long version;
>
> }
>
> etc.
>
>
> However there is a problem with Long, Integer, Short, and bigger one
> with Timestamp.
>
> It seems to be necessary to initialize the Wrappers, otherwise I get an
> exception:
>
> "nested exception is: java.rmi.ServerException: RemoteException occurred
> in server thread; nested exception is: java.rmi.RemoteException: null;
> nested exception is: javax.persistence.OptimisticLockException:
> Exception [TOPLINK-5010] (Oracle TopLink Essentials - 2.0.1 (Build
> b03-fcs (04/05/2008))):
> oracle.toplink.essentials.exceptions.OptimisticLockException Exception
> Description: The object [Entity_at_1fc2f8c] cannot be merged because it has
> changed or been deleted since it was last read. {3}Class> Entity"
>
>
> already at the creation time.
>
> The workaround is simple - you have just to initialize the Wrapper at
> creation time:
>
> @Entity
> public class Entity{
>
> @Id
> @GeneratedValue
> private int id;
> @Version
> private Long version = new Long(0);
>
> }
>
>
> The intiialization shouldn't be necessary: ...= new Long(0);
>
> With Timestamp it seems not to work in general...
>
> I'm creating the objects with em#merge and not em#persist,
>
> regards,
>
> adam
>


-----
---
http://wiki.eclipse.org/User:James.sutherland.oracle.com James Sutherland 
http://www.eclipse.org/eclipselink/
 EclipseLink ,  http://www.oracle.com/technology/products/ias/toplink/
TopLink 
Wiki:  http://wiki.eclipse.org/EclipseLink EclipseLink , 
http://wiki.oracle.com/page/TopLink TopLink 
Forums:  http://forums.oracle.com/forums/forum.jspa?forumID=48 TopLink , 
http://www.nabble.com/EclipseLink-f26430.html EclipseLink 
Book:  http://en.wikibooks.org/wiki/Java_Persistence Java Persistence 
-- 
View this message in context: http://www.nabble.com/Problems-with-optimistic-concurrency--tp17839160p17864586.html
Sent from the java.net - glassfish persistence mailing list archive at Nabble.com.