Hibernate Integration

17 Jun 2016 - 10:03 | Version 25 | | ,

Integrating TransactionsEssentials 4.x and Hibernate

Since release 4.0, we offer built-in examples that demonstrate the integration of Hibernate 4.3+, both with and without Spring. Register here to get them!

Integrating older TransactionsEssentials and Hibernate releases

With Spring

The advantage is that you don't need any JNDI server. The following XML snippet illustrates how to configure TransactionsEssentials 3.1 or higher with Spring and Hibernate.
<?xml version="1.0" encoding="UTF-8"?>


    <!-- configure an Atomikos JTA-aware datasource -->
   <bean id="datasource"
      init-method="init" destroy-method="close">
       <!-- set an arbitrary but unique name for the datasource -->
      <property name="uniqueResourceName"><value>XADBMS</value></property>
            set the underlying driver class to use, 
            in this example case we use Oracle 
      <property name="xaDataSourceClassName">
      <property name="xaProperties">
             set the driver-specific XADataSource properties 
             (check your driver docs for more info)
                        <prop key="user">scott</prop>
                        <prop key="password">tiger</prop>
                        <prop key="URL">...</prop>
       <!-- how many connections in the pool? -->
      <property name="poolSize" value="3"/>

        configure Hibernate to use the Atomikos JTA and 
        datasource for transaction control 
   <bean id="sessionFactory" 
       NOTE: for hibernate 2, use the following class: 

       <!-- add the mapped resources (hbm files) of your application -->
      <property name="mappingResources">

          make sure that hibernate uses the 
          Atomikos datasource (JTA enabled)! 
      <property name="dataSource"><ref bean="datasource"/></property>

       <!-- configure hibernate to use Atomikos TransactionsEssentials -->
      <property name="hibernateProperties">
            <prop key="hibernate.transaction.factory_class">
            <prop key="hibernate.transaction.manager_lookup_class">
             <!-- for hibernate 2, use the following:
             <prop key="hibernate.transaction.manager_lookup_class">
             <!-- add any other hibernate properties you need -->


       configure the Spring hibernate template with the session factory from above 
   <bean id="hibernateTemplate" 
      <property name="sessionFactory"><ref bean="sessionFactory"/></property>


Also see http://fogbugz.atomikos.com/default.asp?community.6.3045.1 for a forum post describing possible issues with the connection release configuration of Hibernate.

Without Spring

See Hibernate 3 Standalone sample for an example application that integrates with Hibernate (without Spring). This approach requires a JNDI server.

With JPA

See http://docs.jboss.org/hibernate/stable/entitymanager/reference/en/html/transactions.html for how to configure the JPA - this page suggests that there should be NO factory class configuration, only a lookup class. So for Hibernate JPA, the factory must be omitted in the above config examples.

With JPA and Infinispan as the Cache

See http://www.javacodegeeks.com/2010/06/gwt-spring-and-hibernate-enter-world-of.html for a blog post describing how to get this to work.

Contact Us

Atomikos Corporate Headquarters
Hoveniersstraat, 39/1, 2800
Mechelen, Belgium

E info@atomikos.com
E sales@atomikos.com
T +3215613055

Subscribe to our newsletter

Never miss an update

Copyright 2016 Atomikos BVBA