AFAIK, there are two types of entity manager.
1. Container managed entity manager
2. Application managed entity manager
- Container managed entity manager
- This type of em uses JTA transaction only
Below is my code:
@PersistenceContext(unitName = "", type = Transaction)
EntityManager em;
public void persist(T entity) {
em.persist(entity)
}
Questions:
There is exception throw when execute the code : TransactionRequireException
Why there is this kind of exception? There is no TransactionRequireException happen after added @Resource UserTransaction to the method persist(). I wonder UserTransaction is belongs to JTA right.
EntityTransaction et = em.getTransaction();
Refer to the above code, Why JTA transaction type cannot invokes getTransaction() ?
Can extended JTA Transaction em use outside of EJB?
- Application managed entity manager
- Utilize JTA Transaction
- Utilize JDBC Transaction(Resource Local Transaction)
Please anyone provide example of source code on JDBC Transaction type.
A JPA persistence unit can either be JTA or RESOURCE_LOCAL.
If you use JTA, then you must use JTA for transaction, either through SessionBeans or by accessing JTA directly.
See,
http://en.wikibooks.org/wiki/Java_Persistence/Runtime#Java_Enterprise_Edition