我试图通过约束验证来持久化实体,当调用持久化时 - 抛出约束并且调用者获取EjbTransactionRolledbackException
......所以我尝试显式调用验证并抛出ConstraintViolationException
/RuntimeException
仍然调用者获取EjbTransactionRolledbackException
......当我抛出MyException
扩展Exception
- 调用者得到MyException
即使我明确表示sc.setRollBackOnly
它仍然发生:(
这不应该是行为。
这是怎么回事?
配置:
Netbeans 6.9.1 Glassfish 3.0.1 JPA 2.0 (EclipseLink) EJB 3.1
谢谢!!!
@Stateless
public class My {
@PersistenceContext
EntityManager em;
@Resource
Validator validator;
public Order checkout(Order order) {
Set<ConstraintViolation<Order>> set = validator.validate(order, Default.class);
if (!set.isEmpty()) {
sc.setRollbackOnly();
//throw new ConstraintViolationException(new HashSet<ConstraintViolation<?>>(set));
throw new RuntimeException();
}
this.em.persist(order);
}