What is the best way to handle ConstraintViolationException using EJB3 and entitymanager in SLSB

here is my code snippet:

@Stateless
public class mySLSB {

@PersistenceContext(unitName = "db")
private EntityManager myEntityManager;

 public void crud(MyEntity myEntity) throws MyException {
  myEntityManager.merge(myEntity);
 }
}

However, this merge can throw a ConstraintViolationException that does not throw a MyException (which gets into the calling servlet).

What is the best way to catch exceptions for sleep mode?

+3
source share
2 answers

However, this merge can throw a ConstraintViolationException that does not throw a MyException (which gets into the calling servlet). What is the best way to catch sleep mode exceptions?

JPA API EntityManager javax.persistence.RollbackException ConstraintViolationException . , RollbackException getCause(), .

+1

- . . , ConstraintViolationException, , . , , . , , - , / .

catch HibernateException . ( , / , ).

, ConstraintViolationException. , , getConstraintName() ConstraintViolationException. ​​.

+1

Source: https://habr.com/ru/post/1772157/


All Articles