Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Optimistic Lock Exception expected

Looking at the code, the merge() is not throwing an error for versioned
objects that were deleted.  Please log a bug for this and post the id, so I
can also vote for it.


Mathias Koehnke - Sun Microsystems wrote:
> 
> Hi,
> 
> Enclosed, you'll find the source code of the entity/main class and log 
> output:
> 
> 
> public class Main {
> 
>      private static EntityManagerFactory emf;
> 
>      public static void main(String[] args) {
>  
> JpaHelper.getServerSession(getEntityManagerFactory()).getProject().assumeExistenceForDoesExist();
> 
>          SimpleEntity entity = new SimpleEntity();
>          entity.setValue("entity");
> 
>          //persist "entity" and create clone "entityCopy"
>          EntityManager em1 = 
> getEntityManagerFactory().createEntityManager();
>          em1.getTransaction().begin();
>          em1.persist(entity);
>          em1.getTransaction().commit();
>          SimpleEntity entityCopy = em1.find(SimpleEntity.class, 
> entity.getId());
>          em1.close();
> 
>          //delete "entity" from database
>          EntityManager em2 = 
> getEntityManagerFactory().createEntityManager();
>          em2.getTransaction().begin();
>          entity = em2.merge(entity);
>          em2.remove(entity);
>          em2.getTransaction().commit();
>          em2.close();
> 
>          //merge clone "entityCopy" and commit
>          EntityManager em3 = 
> getEntityManagerFactory().createEntityManager();
>          em3.getTransaction().begin();
>          entityCopy = em3.merge(entityCopy);
>          em3.lock(entityCopy, LockModeType.WRITE);
>          em3.getTransaction().commit();
>          em3.close();
>      }
> 
>      private static EntityManagerFactory getEntityManagerFactory() {
>          if (emf == null) {
>              emf = 
> Persistence.createEntityManagerFactory("EclipseLinkTestPU");
>          }
>          return emf;
>      }
> 
> 
> 


-----
---
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/Optimistic-Lock-Exception-expected-tp22742662p23078063.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top