2019-12-18
I just had a very similar issue with EclipseLink
, in a Maven
multi module web application running on Weblogic 12c
server and using JTA
.
In the persistence.xml
we are having:
< property name="eclipselink.persistence-context.flush-mode"
value="commit" />
In my case. I had to manually call flush()
on EntityManager
to force flush and the exception to occur at proper time and line (basically in the try block
) to be able to catch it, handle it.
My insert/update/delete query was sitting in my JPA provider cache, and not sent to the database, this exception couldn't occur so the code couldn't caught it.
Automatically, it would have been flushed and the exception would have occured at the end of the transaction boundary, basically at the end of the method in my case, which is obviously far after my try{...}catch(Exception e){...}
block, so I was not able to catch it.
The final caught exception in the log (I have masked some not related info):
javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence Services - x.x.x.v00000000-0000000): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLIntegrityConstraintViolationException: ORA-00001: unique constraint (XXXXX.UNIQUE_KEY_NAME) violated
Related pseudo code:
try {
repository.update(entity);
repository.getEntityManager().flush();
} catch (Exception e ) {
log.info(e.toString());
...
}