Online Training Spring Hibernate Training in Delhi R Programming Training Course Big Data and Hadoop Training Java Training

Hibernate jta

In this section, you will learn about jta with Hibernate.


How to write hello world example program in Hibernate? How to create one to one relationship in Hibernate 4 with Annotation? How to calculate minimum in Hibernate using the min() Function Hibernate 4.3.4 Released: Hibernate 4.3.4.Final Maven dependency Hibernate 4.3 Hello World: Example How to create SessionFactory in Hibernate 4.3.1? Hibernate 4 Hello World: Example of Hello World program Hibernate 4 create Session Factory: Example of creating Session Factory in Hibernate 4 Hibernate 4.3 and JPA 2.1 Example What is Hibernate in Java? Hibernate Overview and Architecture What is JPA 2.1? Hibernate 4.3.0.Final Maven dependency Hibernate 4.3 ORM Features Hibernate 4.3 Tutorial Hibernate Criteria average example Hibernate Criteria load all objects from table Hibernate Criteria Hibernate beginner tutorial Hibernate Session.delete() Example Hibernate save or update method example Hibernate Load Example Hibernate save Example - Rose India Hibernate 4 tutorials Hibernate Example Step by Step in Eclipse Hibernate Configuration files Setup Hibernate Environment Hibernate Architecture Hibernate Overview Hibernate 4.2 Tutorial Hibernate 4 Annotations Tutorial Hibernate 4 AnnotationSessionFactoryBean hibernate versions hibernate jndi hibernate tomcat hibernate metamodel generator hibernate entity Seam Hibernate C3P0 Hibernate hibernate shard hibernate means temporal hibernate jsf hibernate spring j2ee hibernate spring hibernate encrypted password alias_to_entity_map hibernate temporal jsf spring hibernate hibernate by example hibernate repository hibernate sample code

Hibernate jta

In this section, you will learn about jta with Hibernate.


JTA stands for Java transaction API. It permits you to define transactions in a way which is free from transaction manager implementation. The Application Server applies the transaction manager with the JTS (Java Transaction Service). Still you can't call JTS functions directly. Rather, it calls the JTA function which afterward invokes the lower level JTS routines.

Why use JTA transaction ?

 The Java EE transaction manager controls a JTA transaction. The JTA transaction is useful where you need to update various database of different vendor. You can't work with different database using a specific DBMS's transaction manager.

JTA Limitation

Nested transaction is not supported by Java EE transaction manager. You can't initiate another transaction without ending the previously transaction.

JTA transaction methods

To perform a JTA transaction, you can implement begin, commit, and rollback methods of the javax.transaction.UserTransaction interface.


Given below sample code about how to employ JTA transactions with JBoss 6 server, Spring 3 and Hibernate 3 :


Notice carefully the <tx> and <bean> tag  of the below Spring configuration file :

<bean id="entityManagerFactory"
	<property name="persistenceUnitName" value="Writing" />

<bean id="writingDao" class="net.roseindia.dao.WritingDaoImpl" />

<bean id="writingBean" class="net.roseindia.beans.WritingBean" scope="singleton">
	<property name="writingDao" ref="writingDao" />

<tx:annotation-driven transaction-manager="myTransactionManager" />
<tx:jta-transaction-manager />

<bean id="myTransactionManager"
class="org.springframework.transaction.jta.JtaTransactionManager" />

<bean class=" " />


Notice carefully the transaction-type of the <persistence-unit> tag and also first <property> tag of the  <properties> tag.

<persistence-unit name="Writing" transaction-type="JTA">

		<property name="hibernate.transaction.manager_lookup_class"
		value="org.hibernate.transaction.JBossTransactionManagerLookup" />
		<property name="hibernate.show_sql" value="true" />
		<property name="hibernate.format_sql" value="true" />
		<property name="" value="create" />


The DAO implementation classes should be coded like this :

private EntityManager em;

@Transactional(readOnly = true)
public List<Tutorial> retrieveAllTutorials() {
	return em.createQuery("from Tutorial").getResultList();



Share on Google+Share on Google+

Hibernate jta

Posted on: April 19, 2012 If you enjoyed this post then why not add us on Google+? Add us to your Circles



Discuss: Hibernate jta  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image