JBoss AS 6에서 JBoss AS 7로 마이그레이션 프로세스를 진행하고 있으며 테스트에 문제가 있습니다. 의 간단한 엔티티 EJB 가정 해 보자 :에서JBoss AS 7에서 PersistenceException 또는 ConstraintViolationException을 catch합니다.
@Entity public class MyTest implements Serializable
{
@Id @GeneratedValue(strategy=GenerationType.AUTO)
private long id;
@NotNull
private String headline;
} //getter/setter
을 내 @Stateless Bean
내가 (전 JBoss5 및 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:");
// Further investigation of Exception e,
// then throw MyContraintViolationException
}
}
난을 위반하지 않은 경우이 잘 작동 @NotNull
제약 조건. headline==null
경우에, 나는 예외를 얻을,하지만 내 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.
[email protected] >: 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}'}
나는 오류 메시지가 보스의 이전 버전보다 훨씬 더 자세한 것을 볼 수 행복 해요,하지만 내가 어떻게 할 수 javax.validation.ConstraintViolationException
을 붙잡고 내 자신을 던져 MyContraintViolationException
? 심지어 디버그 메시지 ***** exception
은 이 아니며이 인쇄되어 있습니다. 당신이 메시지와 예외의 스택 트레이스를 읽는다면