Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Persistence unit as RESOURCE_LOCAL or JTA?

I have queries as below:

  1. What is the difference of these two?
  2. Are both of these supported by all databases?
  3. Are JPA TransactionManager and JTA TransactionManager different?
like image 224
cometta Avatar asked Dec 26 '09 03:12

cometta


People also ask

What is transaction type RESOURCE_LOCAL?

In general, in Java EE environments, a transaction-type of RESOURCE_LOCAL assumes that a non-JTA datasource will be provided. In a Java EE environment, if this element is not specified, the default is JTA. In a Java SE environment, if this element is not specified, the default is RESOURCE_LOCAL."

What is a persistence unit?

A persistence unit defines a set of all entity classes that are managed by EntityManager instances in an application. This set of entity classes represents the data contained within a single data store. Persistence units are defined by the persistence.xml configuration file.

What is persistence units xml?

The persistence. xml configuration file is used to configure a given JPA Persistence Unit. The Persistence Unit defines all the metadata required to bootstrap an EntityManagerFactory , like entity mappings, data source, and transaction settings, as well as JPA provider configuration properties.


1 Answers

JPA implementations have the choice of managing transactions themselves (RESOURCE_LOCAL), or having them managed by the application server's JTA implementation.

In most cases, RESOURCE_LOCAL is fine. This would use basic JDBC-level transactions. The downside is that the transaction is local to the JPA persistence unit, so if you want a transaction that spans multiple persistence units (or other databases), then RESOURCE_LOCAL may not be good enough.

JTA is also used for managing transactions across systems like JMS and JCA, but that's fairly exotic usage for most of us.

To use JTA, you need support for it in your application server, and also support from the JDBC driver.

like image 113
skaffman Avatar answered Sep 20 '22 15:09

skaffman