I am involved in the transition from JBoss AS 6 to JBoss AS 7 and am experiencing problems with my tests. Let a simple EJB be assumed:
@Entity public class MyTest implements Serializable { @Id @GeneratedValue(strategy=GenerationType.AUTO) private long id; @NotNull private String headline; }
In my @Stateless Bean I am doing something like this (as before with JBoss5 and JBoss6):
@Inject private EntityManager em; public <T extends Object> T persist(T o) throws MyContraintViolationException { System.out.println("***************** persist:"); try { em.persist(o); } catch (Exception e) { System.out.println("*************** exception:");
This works fine if I do not violate the @NotNull restriction. If headline==null , I get exceptions, but do not enter the catch :
12:19:45 INFO ******************** persist: 12:19:45 WARN [com.arjuna.ats.arjuna] (management-handler-threads - 2) ARJUNA012125: TwoPhaseCoordinator.beforeCompletion - failed for SynchronizationImple< 0:ffffc0a801fb:4f969a6e:4f058744:9, org.hibernate.engine.transaction.synchronization.internal. RegisteredSynchronization@38eb9b73 >: javax.persistence.PersistenceException: error during managed flush ... Caused by: javax.validation.ConstraintViolationException: Validation failed for classes [my.test.MyTest] during persist time for groups [javax.validation.groups.Default, ] List of constraint violations:[ ConstraintViolationImpl{interpolatedMessage='kann nicht null sein', propertyPath=headline, rootBeanClass=class my.test.MyTest, messageTemplate='{javax.validation.constraints.NotNull.message}'}
I am glad to see that the error message is much more detailed than in previous versions of JBoss, but how can I catch javax.validation.ConstraintViolationException and throw my own MyContraintViolationException ? Even the debug message ***** exception not printed.
source share