Our application is using JPA and persistent provider was Toplink-essensials (built-in in glassfish).
For some reasons we decided to switch to Hibernate as a persistent provider.
After doing this we've got following problems with our integration tests based on Spring's AbstractJPATests.
For example simple test CRUD scenario fails this way:
we create some entity, get it by id then. Then we alter some of its fields and try to save it for further look up and check if fields entity was saved with new field values.
But on update method call we get:
org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [...Account#7379]
at org.hibernate.persister.entity.AbstractEntityPersister.check(AbstractEntityPersister.java:1769)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2412)
at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2312)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2612)
at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:96)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:168)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:304)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:193)
at $Proxy46.flush(Unknown Source)
at ...AccountServiceBean.update(AccountServiceBean.java:275)
Full stack-trace shows that exception is thrown when flush() method of EntityManager is called. (in AccountServiceBean.java:275)
This never happend when we used toplink.
So what can be the cause of this exception???
[Message sent by forum member 'olperv' (olperv)]
http://forums.java.net/jive/thread.jspa?messageID=315000