Yes and no.
More exactly, the behavior without the Transactional annotation is equivalent to TxType.SUPPORTS - it can run both in transaction if it exists, or outside of transaction if no transaction exists. The difference is in how the bean is called - if it's called from another bean that creates a transaction, then it will run in that transaction. While using UserTransaction requires that no transaction is available, even if the bean is called from another bean that creates a transaction. Therefore it's better to turn on TxType.NOT_SUPPORTED explicitly, which will suspend a transaction if it exists, and will allow using UserTransaction in all cases, not only if the bean is used outside of the transaction.
In code, it would look like this:
@RequestScoped
@Transactional
class CallingBean {
@Inject
BeanWithUserTransaction anotherBean;
void doSomethingInTransaction() {
anotherBean.doSomethingInUserTransaction()
}
}
With the code above, the following will give you an exception when using UserTransaction, if no @Transactional annotation is present:
@RequestScoped
class
BeanWithUserTransaction {
@Inject
UserTransaction tx;
void doSomethingInUserTransaction() {
tx.begin(); // here will be exception
}
}
To fix this, you need to use @Transactional(Transactional.TxType.NOT_SUPPORTED) on the BeanWithUserTransaction class.
Ondro