My runtime exception
@ApplicationException(rollback=false)
public class UncheckedException extends RuntimeException {}
My EJB code
@Stateless
@Transactional(TxType.REQUIRES_NEW)
public class ContainerManagedTransactionBean {
@PersistenceContext EntityManager em;
public void insertAndThrowUnchecked() throws UncheckedException {
em.persist(new Entry());
throw new UncheckedException();
}
}
My another EJB is client
@Singleton
@Startup
@Transactional(TxType.NOT_SUPPORTED)
public class Start {
@EJB
ContainerManagedTransactionBean bean;
@PostConstruct
public void start() {
//...
try {
bean.insertAndThrowUnchecked();
} catch (Exception e) {
System.out.println("Start unchecked exception catched");
}
}
Could someone explain me why insertAndThrowUnchecked is rolled back? In similar case, when exception is checked,
@ApplicationException(rollback=false)
public class CheckedException extends Exception {}
transaction is committed.
Working example is here: http://ift.tt/1IDND3k
I will appreciate clear explanation and link to proper part of EJB specification
Aucun commentaire:
Enregistrer un commentaire