Non JTA transactions with Hibernate, JBoss 6 and Spring 3

Hi there, I'm going to show you how to set up your JEE project to use non-JTA transactions with JBoss AS 6, Spring 3, Hibernate and JPA annotations.
Please note - integration tests don't require a database server running - they instantiate their own in-memory database server.

(Interested in JTA with Hibernate 3, Spring 3 and JBoss 6 instead?)


This is our Spring config file.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
   xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"

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

   <bean id="dogsDao" class="me.m1key.springtx.dao.DogsDaoImpl" />

   <bean id="dogsBean" class="me.m1key.springtx.beans.DogsBean"
       <property name="dogsDao" ref="dogsDao" />

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

   <bean id="myTransactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
       <property name="entityManagerFactory" ref="entityManagerFactory" />

       class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
What's worth noting is the transaction manager. Because we are not using JTA, we must explicitly provide the transaction manager for the application to use.


Next, let's look at our persistence.xml file.

<persistence-unit name="Dogs" transaction-type="RESOURCE_LOCAL">       <non-jta-data-source>java:/DogsDS</non-jta-data-source>

          <property name="hibernate.show_sql" value="true" />
          <property name="hibernate.format_sql" value="true" />
          <property name="hibernate.hbm2ddl.auto" value="create" />
What we have here is a persistence unit called Dogs. The transaction type is RESOURCE_LOCAL - that tells the container not to use JTA. Below we specify JNDI data source name, entity classes and some properties. Note I don't have to specify typical data source properties (user name, password, url) - that's because they don't belong here. We define data source properties in JBoss.


This is a standard JBoss data source file. It must be called X-ds.xml.

<?xml version="1.0" encoding="UTF-8"?>


       <track-statements />
           <type-mapping>Hypersonic SQL</type-mapping>
Nice and simple.


Last but not least, DAO that uses this setup.

   private EntityManager em;

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

That's it! To run this example you need a database server running. I'm using HSQLDB. You can download source code and there is a batch file there that runs this HSQLDB server. The application is to be deployed on JBoss 6.

You call the transactional operation by accessing http://localhost:8080/springtx-nonjta-0.0.1-SNAPSHOT/myurl.


  1. Before Commenting, I wanna say thank you for providing this great information. I feel too good to read it this awesome blog. Keep sharing this type of content. 토토사이트

  2. We have read your blog. It was really informative and we have collected much knowledge that has assisted me a lot. People can also visit our website… 온라인경마

  3. I was very interested in the article. it’s quite inspiring I should admit. I like visiting you site since I always come across interesting articles like this one. 카지노

  4. Thank you for posting such a great article! I found your website perfect for my needs. It contains wonderful and helpful posts. Keep up the good work!. Thank you for this wonderful Article! 토토사이트