The terms "jta-datasource" and "resusce-local datasource" are a bit vague for me.
I think you are really referring to jta-datasource and non-jta-datasource . In short:
- If the transaction type of the continuity unit is JTA, the
jta-datasource used to declare the JNDI name of the JTA data source that will be used to receive the connections. This is a common case. - If the persistence unit transaction type is locally resource,
non-jta-data-source should be used to declare a JNDI name for a data source other than JTA.
- The same database can be called a jta-datasource resource or a local data source resource.
It is right. And I didnโt mention it above, but some providers even allow you to declare both jta-datasource and a non-jta-datasource and use later for optimized reading through connections other than JTA (i.e. t be connected to the current transaction JTA).
- If referred to as jta-datasource, then beans / other classes can use JTA. Therefore, the UserTransaction interface.
The first part is correct, the last part is not complete. From the EJB 3.0 specification, section 13.3.4 Enterprise beans Using managed container transaction demarcation :
Bean enterprise business methods [...] should not attempt to obtain or use the javax.transaction.UserTransaction interface.
And section 16.12 of the UserTransaction Interface :
The container should not use the UserTransaction interface for enterprise beans, which is not allowed to use this interface.
In other words, the UserTransaction interface UserTransaction not available for the CMT beans enterprise.
- You cannot use CMT / BMT if the data source is a local resource
The text is a bit confusing, but I would say that this is not entirely correct. From the JPA 1.0 specification, section ยง 5.5 Transaction management :
An application-driven object manager can be either a JTA entity manager or a local resource manager.
...
Both JTA object managers and local object administrators must be supported in Java EE web containers and EJB containers. An EJB environment typically uses the JTA object manager.
And section 6.2.1.2 transaction type
The transaction-type attribute is used to indicate whether the entity managers provided by the factory entity manager for the persistence unit should be JTA entity managers or resource and local entity managers. The value of this element is JTA or RESOURCE_LOCAL . The JTA transaction type assumes that a JTA data source will be provided - either as indicated by the jta-data-source element or provided by the container. In general, in Java EE environments, a transaction-type of RESOURCE_LOCAL assumes that a non-JTA data source will be provided. In Java EE, if this item is not specified, JTA is used by default.
So you can use a managed application manager that can be a local resource manager (you have to enter EntityManagerFactory to get EM from it in this case) and it will not be part of the JTA transaction.See this (very interesting) discussion .
- If referred to as a local data source resource, transactions are not JTAs. The code can use the EntityTransaction interface, but not the UserTransaction interface.
Again, the wording is a bit confusing, but I would say that it is correct.