I have an @StatelessEJB with an interface @WebServiceusing container-managed transactions, which means that transactions are automatically committed by the container after the method is called if it does not throw a system exception.
If I try to execute EntityManager.persist(...)two objects with the same value for a column with a unique constraint on it, the container will call PersistenceExceptionfor the client when committing outside of my code. How can I catch this exception so that I can recover my own application exception?
Do I have to commit a transaction manually in my methods to catch exceptions when committing? (And is there a EntityManager.flush()right way to do this?) If so, then what is the point of container-driven transactions?
source
share