Skip to main content

Catching java.sql.SQLException: ORA-00001: unique constraint

1 reply [Last post]
Joined: 2006-11-10
Points: 0


Can you explain me how the catch a unique constraint SQL exception from a session stateless bean that manipulates entities trought the persistance context.
I would like to inform my remote client that the EJBException is due to an SQL error and providing the error code.

At the moment, my session bean is not informed that an SQL exception occured.

Thank you in advance for your help.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2005-03-30
Points: 0

There is no spec defined way to extract the SQL exception from a PersistenceException. You may be able to extract the SQLException by recurssively walking up the cause tree (by calling getCause()) from a PersistenceException.

By the way, unique constrain violation exception is raised by database backend, so it occurs when changes are sent to database during implicit or explicit flush(). For you to catch the exception of your interest, you have to call flush() in your code.

hope that helps,