Hello,
I am having a problem with the @Version tag in combination with a timestamp (mysql5, hibernate 3.2.2)
I have a simple bean with id, name and version attributes.
The following code fragment
EntityManagerFactory emf = Persistence.createEntityManagerFactory(System.getProperty("EntityManager"));
EntityManager em=emf.createEntityManager();
EntityTransaction tx1=em.getTransaction();
tx1.begin();
Role r1=new Role();
r1.setName("role");
em.persist(r1);
tx1.commit();
em.clear();
EntityTransaction tx2=em.getTransaction();
tx2.begin();
r1=em.merge(r1);
em.remove(r1);
tx2.commit();
When I have a int @Version attribute the code seems to work fine, but with a Timestamp version I get
javax.persistence.OptimisticLockException: org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [com.luma.w2p.model.Role#5]
at org.hibernate.ejb.AbstractEntityManagerImpl.wrapStaleStateException(AbstractEntityManagerImpl.java:645)
at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:599)
at org.hibernate.ejb.AbstractEntityManagerImpl.merge(AbstractEntityManagerImpl.java:236)
Is there something wrong with the code? Or is this a (known) issue in Hibernate (the glassfish/toplink ri) also works for Timestamp version attribute.
Thanks,
Peter
|