I've added a unique constraint to a table as follows:
My entity:
I then catch the exception in my
EJB method create():
My EJB:
I then try to add "John Doe" twice, triggering a PersistenceException to be thrown by persist(). In my
server log I can see that there is an internal exception thrown MySQLIntegrityConstraintViolationException,
as you'd expect:
The problem is that I don't know how to access this internal level of detail about the exception, all I know
is that there is a PersistenceException, not that there's been a MySQLIntegrityConstraintViolationException.
At present my code handles an integrity constraint violation in exactly the same way as if I've forgotten
to start the database server, what I want to do is to separate out "soft" errors related to user input from
hard errors such as coding errors and major environmental problems.
If anyone knows how to achieve this I'll be eternally grateful.
Thanks,
Brendan.