Hi,
I have a an ejb that insert a new record if it doesn't exist yet (in a new transaction i.e. REQUIRES_NEW)
How I accomplish this is by catching the EntityExistsException and just ignore it if I ever encounter it.
However, writing the unit test didn't seem to work and I always get this exception:
ERROR [org.hibernate.event.def.AbstractFlushingEventListener] Could not synchronize database state with session
org.hibernate.exception.ConstraintViolationException: could not insert: [com.eg.TestEntity]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2202)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2595)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:51)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:139)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:297)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
It appears that even if I am catching that exception, a separate Exception Reporter thread seems to be notifying the app server and rolling back the transaction. is this really what is happening?
Is there any way I can accomplish this logic by just purely catching the exception and ignoring it?
Any replies will be appreciated.
|