Mirea Vasile
Mirea Vasile

Reputation: 421

JTA Transactions with JPA(Hibernate)

If I use in persistence.xml a transaction-type="RESOURCE_LOCAL" then I can avoid using a non-jta-data-source by using the properties:

<properties>
  <property name="hibernate.bytecode.use_reflection_optimizer" value="false"/>
  <property name="hibernate.connection.driver_class" value="oracle.jdbc.OracleDriver"/>
  <property name="hibernate.connection.password" value="passsample"/>
  <property name="hibernate.connection.url" value="jdbc:oracle:thin:urlsample"/>
  <property name="hibernate.connection.username" value="usersample"/>
  <property name="hibernate.default_schema" value="schemasample"/>
  <property name="hibernate.dialect" value="org.hibernate.dialect.OracleDialect"/>        
</properties>

The question is if I use a transaction-type="JTA" then is mandatory to use a jta-data-source ? If is mandatory please tell me why ? If not what I need to do ?

I am trying to configure an application with glassfish and everything works fine with an external datasource (configured in glassfish), but I would like to configure everything in spring and with the help of properties.

Any solution for this ?

Upvotes: 2

Views: 5615

Answers (1)

Nayan Wadekar
Nayan Wadekar

Reputation: 11602

For JTA transaction type, you have to define <jta-data-source>. But if you are using RESOURCE_LOCAL(non-JTA), then it is <non-jta-data-source>.

JTA is the default transaction type, if none is specified. These element is used to specify the data source, generally a global JNDI name for referencing the data source.

Transaction in JTA can traverse across multiple persistent units/databases & external environment (like JMS). Typically, JTA is used in Java EE & RESOURCE_LOCAL is used in Java SE environment.

Upvotes: 1

Related Questions