Hi. All container-managed entity managers are JTA managers. An application-managed entity manager may be either JTA or resource-local, and they are always extended. The difference is that when it is JTA, it simply is used in a distributed transaction with EJB calls, Timer creations, other resource managers and so on. When the UserTransaction (either container-managed or bean-managed, it doesn't really matter) is rolled back, all of the mentioned operations are rolled back. If you used resource-local manager (EntityTransaction interface to demarcate transactions), the rollback on the UserTransaction would not influence the entity manager operations. Hence, you will most likely use JTA in Java EE, whereas resource-local are designed to be usable in Java SE, when there is possibly no JTA implementation available.
One more note - when you use an application-managed JTA entity manager and create them outside an active JTA transaction (for example, when you inject a manager factory and in @PostConstruct you create the entity manager), you call joinTransaction() before you call refresh(), persist(), merge() or remove(), so that these operations don't throw TransactionRequiredException. The JTA transaction may either be container- or bean-managed.
Does this make sense?
Can you tell me in example that how to create an application-managed entity manager with JTA and resource-local transactions? This is the point what I couldn't understand.
then may I know what is the difference between container-managed entity managers JTA and application-managed entity managers JTA?
Are there both same in terms of JTA?
In the "container-managed entity manager" the container care about the life cycle for the involved resources (or more precisely the resource manager connection factory) and the application is focus only on the business. In the "application mode" the application (you can read here the developer) must care about the resource life cycle (e.g. it must close the factory), so in this case the application must focus on business and on resource life cycle.
I roughly get your meaning. from the transaction model point of view, these 2 are no difference.
while from the entity point of view, there is the difference. Am I correct?