-
1. Re: JTA does not rollback transaction when RuntimeException thrown in another bean?
jaikiran Jun 14, 2019 1:34 AM (in response to alireza.alallah)I don't know if this is a problem in the sample code you pasted or it really is an issue in your application, but, there's really no exception being thrown since, the exception is just being caught and the stacktrace printed out:
try {
throw new RunTimeException("error occurred!!");
} catch(RunTimeException e) {
e.printStacktrace();
}
So it's pretty much as if there's no exception
-
2. Re: JTA does not rollback transaction when RuntimeException thrown in another bean?
zhfeng Jun 14, 2019 2:00 AM (in response to alireza.alallah)Also I think you should add the @Transactional annotation on the BeanA::handle()
-
3. Re: JTA does not rollback transaction when RuntimeException thrown in another bean?
alireza.alallah Jun 16, 2019 2:31 PM (in response to zhfeng)I think that in EJB by default is transactional , I am right?
-
4. Re: JTA does not rollback transaction when RuntimeException thrown in another bean?
alireza.alallah Jun 16, 2019 2:33 PM (in response to jaikiran)In above example if modify my code as below:
@Stateless
public class BeanA {
@PersistenceContext(unitName = "primary")
private EntityManager em;
@EJB private BeanB beanB;
public void handle() {
EntityA entity= new EntityA();
....
try {
throw new RunTimeException("error occurred!!");
} catch(RunTimeException e) {
e.printStacktrace();
}
em.persist(entity); //Transaction does not rollback and saved entity
}
}
Then container thrown exception that Transaction is not present
-
5. Re: JTA does not rollback transaction when RuntimeException thrown in another bean?
jaikiran Jun 17, 2019 12:27 AM (in response to alireza.alallah)1 of 1 people found this helpfulalireza.alallah wrote:
I think that in EJB by default is transactional , I am right?
That's correct.
Then container thrown exception that Transaction is not present
Please post the complete exception stacktrace and the client code where you do the lookup and invocation on the EJB.