posted 15 years ago
Hi,
I want to know if it is possible to get hold of the underlying sql exceptions when using enityManager to persist data.
In my example, I try to insert a duplicate row into the database, and I would like to receive a duplicate row exception.
Instead I get returned a javax.persistence.PersistenceException and embeded in the text is the sql exception :
Caught an exception javax.persistence.PersistenceException: Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2.0.1 (Build b04-fcs (04/11/2008))): oracle.toplink.essentials.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '123' for key 2
Error Code: 1062
Is there anyway I can get the error code so that I can deal with the exception in the appropriate way.
My code is shown below:
Thanks