EntityManager exception handling in session bean
问题 I have a managed stateless session bean with injected EntityManager em. What I am trying to do is to have a database table with unique column. Then I run some algorithm which is trying to insert an entity. If entity exists however it will update it or skip it. I would like to have something like this: try { em.persist(cd); em.flush(); } catch (PersistenceException e) { // Check if the exception is DatabaseException and ConstraintViolation // Update instead or skip it } Problem is that I am