Atomikos Forum

newbie needs help getting started

Greetings all,

I'm trying to upgrade my functioning standalone desktop Java/Spring3x/Hibernate3x/Maven/MySQL5x/Eclipse app
from using Hibernate for my ORM to JTA.  I chose Atomikos 3.6.4 for my external transaction manager as JOTM is no
longer supported in Spring 3.x  .

Here's what I have so far:

pom.xml
[code]
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
                            http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>trial_B_spring</groupId>
  <artifactId>trial_B_spring</artifactId>
  <version>0.0.1-SNAPSHOT</version>
 
  <name>trial_B_spring Model Objects</name>
  <description>maybe this will work</description>

  <properties>
    <springVersion>3.1.1.RELEASE</springVersion>
    <slf4jVersion>1.6.1</slf4jVersion>
    <powermockVersion>1.4.8</powermockVersion>
  </properties>

  <dependencies>
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>servlet-api</artifactId>
      <version>2.5</version>
    </dependency>

    <!-- Spring -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-core</artifactId>
      <version>${springVersion}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-beans</artifactId>
      <version>${springVersion}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-aop</artifactId>
      <version>${springVersion}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context</artifactId>
      <version>${springVersion}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-tx</artifactId>
      <version>${springVersion}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-test</artifactId>
      <version>${springVersion}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-orm</artifactId>
      <version>${springVersion}</version>
    </dependency>
    <dependency>
      <groupId>javax.annotation</groupId>  <!-- in conjunction with javax.annotation.Resource -->
      <artifactId>jsr250-api</artifactId>  <!-- for using @Resource for explicit bean injecting -->
      <version>1.0</version>
    </dependency>   
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-jdbc</artifactId>
      <version>${springVersion}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-instrument</artifactId>
      <version>${springVersion}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-instrument-tomcat</artifactId>
      <version>${springVersion}</version>
    </dependency>
    <dependency>
      <groupId>com.atomikos</groupId>
      <artifactId>transactions</artifactId>
      <version>3.6.4</version>
    </dependency>
    <dependency>
      <groupId>com.atomikos</groupId>
      <artifactId>transactions-api</artifactId>
      <version>3.6.4</version>
    </dependency>
    <dependency>
      <groupId>com.atomikos</groupId>
      <artifactId>transactions-jta</artifactId>
      <version>3.6.4</version>
    </dependency>
    <dependency>
      <groupId>com.atomikos</groupId>
      <artifactId>transactions-jms</artifactId>
      <version>3.6.4</version>
    </dependency>
    <dependency>
      <groupId>com.atomikos</groupId>
      <artifactId>transactions-hibernate3</artifactId>
      <version>3.6.4</version>
      <exclusions>
        <exclusion>
          <groupId>org.hibernate</groupId>
          <artifactId>hibernate</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupId>com.atomikos</groupId>
      <artifactId>atomikos-util</artifactId>
      <version>3.6.4</version>
    </dependency>

    <!-- Hibernate -->
    <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-annotations</artifactId>
      <version>3.5.6-Final</version>
      <exclusions>
        <exclusion>
          <groupId>javax.transaction</groupId>
          <artifactId>jta</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-commons-annotations</artifactId>
      <version>3.2.0.Final</version>
    </dependency>
    <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-validator</artifactId>
      <version>4.1.0.Final</version>
    </dependency>
    <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-entitymanager</artifactId>
      <version>3.5.6-Final</version>
    </dependency>

    <!-- databases -->
    <dependency>
      <groupId>c3p0</groupId>
      <artifactId>c3p0</artifactId>
      <version>0.9.1.2</version>
    </dependency>
    <dependency>
      <groupId>hsqldb</groupId>
      <artifactId>hsqldb</artifactId>
      <version>1.8.0.10</version>
    </dependency>
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>5.1.6</version>
    </dependency>

    <!-- Additional Dependencies -->
    <dependency>
      <groupId>org.freemarker</groupId>
      <artifactId>freemarker</artifactId>
      <version>[2.3.16,2.4)</version>
    </dependency>

    <!-- Commons -->
    <dependency>
      <groupId>commons-io</groupId>
      <artifactId>commons-io</artifactId>
      <version>1.4</version>
    </dependency>
    <dependency>
      <groupId>commons-codec</groupId>
      <artifactId>commons-codec</artifactId>
      <version>1.5</version>
    </dependency>
    <dependency>
      <groupId>commons-lang</groupId>
      <artifactId>commons-lang</artifactId>
      <version>2.4</version>
    </dependency>
    <dependency>
      <groupId>commons-collections</groupId>
      <artifactId>commons-collections</artifactId>
      <version>3.1</version>
    </dependency>
    <dependency>
      <groupId>commons-logging</groupId>
      <artifactId>commons-logging</artifactId>
      <version>1.1.1</version>
    </dependency>
    <dependency>
      <groupId>commons-logging</groupId>
      <artifactId>commons-logging-api</artifactId>
      <version>1.1</version>
    </dependency>
    <dependency>
      <groupId>commons-configuration</groupId>
      <artifactId>commons-configuration</artifactId>
      <version>1.5</version>
    </dependency>
   
    <!-- Logging and testing -->
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.8</version>      <!--  only v4.4 works with Spring 2.5.6, use 4.8 with Spring 3.0.5.RELEASE -->
    </dependency>
    <dependency>
      <groupId>log4j</groupId>
      <artifactId>log4j</artifactId>
      <version>1.2.12</version>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
      <version>1.5.8</version>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-log4j12</artifactId>
      <version>1.5.8</version>
    </dependency>
    <dependency>
      <groupId>org.easymock</groupId>
      <artifactId>easymockclassextension</artifactId>
      <version>2.3</version>
      <exclusions>
        <exclusion>
          <groupId>cglib</groupId>
          <artifactId>cglib-nodep</artifactId>
        </exclusion>
      </exclusions>
    </dependency>   

    <!-- other dependencies -->
    <dependency>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-compiler-plugin</artifactId>
      <version>2.2</version>
    </dependency>
   
    <dependency>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-shade-plugin</artifactId>
      <version>1.5</version>
    </dependency>

  </dependencies>
  .....
</project>
[/code]

ApplicationContext.xml
[code]
<?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:aop="http://www.springframework.org/schema/aop"
  xmlns:context="http://www.springframework.org/schema/context"
  xmlns:lang="http://www.springframework.org/schema/lang"
  xmlns:p="http://www.springframework.org/schema/p"
  xmlns:tx="http://www.springframework.org/schema/tx"
  xmlns:util="http://www.springframework.org/schema/util"
  xsi:schemaLocation="http://www.springframework.org/schema/beans
                      http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
                      http://www.springframework.org/schema/aop
                      http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
                      http://www.springframework.org/schema/context
                      http://www.springframework.org/schema/context/spring-context-3.1.xsd
                      http://www.springframework.org/schema/lang
                      http://www.springframework.org/schema/lang/spring-lang-3.1.xsd
                      http://www.springframework.org/schema/tx
                      http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
                      http://www.springframework.org/schema/util
                      http://www.springframework.org/schema/util/spring-util-3.1.xsd"
          default-autowire="byName">

  <!--  Activates various annotations to be detected in bean classes -->
  <context:annotation-config />
   
  <!-- Scan packages for components, services, repositories etc -->
  <context:component-scan base-package="vdms"/>
 
                <!-- Atomikos config start -->
                <!-- Atomikos config start -->
                <!-- Atomikos config start -->
  <bean id="userTransactionService"  class="com.atomikos.icatch.config.UserTransactionServiceImp"
        init-method="init"
        destroy-method="shutdownForce">
    <constructor-arg>
        <!-- IMPORTANT: specify all Atomikos properties here -->
        <props>
            <prop key="com.atomikos.icatch.service">com.atomikos.icatch.standalone.UserTransactionServiceFactory</prop>
        </props>
    </constructor-arg>
  </bean>
 
  <!--  standalone apps or webapps running inside Tomcat need an external transaction manager to use JTA -->
  <!--    I chose to use atomikos  as jotm is not supported in Spring 3.x -->
  <bean id="atomikosUsrTx"  class="com.atomikos.icatch.jta.UserTransactionImp"
        depends-on="userTransactionService" />
       
  <bean id="atomikosTxMgr"  class="com.atomikos.icatch.jta.UserTransactionManager"
        init-method="init"
        destroy-method="close"
        depends-on="userTransactionService">
    <!-- IMPORTANT: disable startup because the userTransactionService above does this -->
    <property name="startupTransactionService" value="false"/>
  </bean>
 
  <bean id="jtaTxManager" class="org.springframework.transaction.jta.JtaTransactionManager" depends-on="userTransactionService">
    <property name="userTransaction"                ref="atomikosUsrTx" />
    <property name="transactionManager"            ref="atomikosTxMgr" />
    <property name="transactionSynchronizationName" value="SYNCHRONIZATION_ON_ACTUAL_TRANSACTION" />
  </bean>
                <!-- Atomikos config finish -->
                <!-- Atomikos config finish -->
                <!-- Atomikos config finish -->

  <bean id="databasePropertiesServerB"
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location"          value="classpath:databaseServerB.properties" />
    <property name="placeholderPrefix" value="$dbServerB{" />
    <property name="placeholderSuffix" value="}" />
  </bean>

  <bean id="dataSourceServerB" class="com.atomikos.jdbc.AtomikosDataSourceBean" init-method="init" destroy-method="close">
    <property name="uniqueResourceName"><value>XADBMS</value></property>
    <property name="xaDataSourceClassName"><value>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</value></property>
  </bean>

  <!-- Hibernate session factory -->
  <bean id="sessionFactoryB"
    class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    <property name="useTransactionAwareDataSource" value="true" />
    <property name="dataSource"        ref="dataSourceServerB" />
    <property name="hibernateProperties">
      <props>
        <prop key="hibernate.dialect">$dbServerB{hibernate.dialect}</prop>
        <prop key="hibernate.hbm2ddl.auto">$dbServerB{hibernate.hbm2ddl.auto}</prop>
        <prop key="hibernate.connection.driver_class">$dbServerB{hibernate.connection.driver_class}</prop>
        <prop key="hibernate.connection.url">$dbServerB{hibernate.connection.url}</prop>
        <prop key="hibernate.connection.username">$dbServerB{hibernate.connection.username}</prop>
        <prop key="hibernate.connection.password">$dbServerB{hibernate.connection.password}</prop>
        <prop key="hibernate.connection.release_mode">$dbServerB{hibernate.connection.release_mode}</prop>
        <prop key="hibernate.cache.provider_class">$dbServerB{hibernate.cache.provider_class}</prop>
        <prop key="hibernate.c3p0.min_size">$dbServerB{hibernate.c3p0.min_size}</prop>
        <prop key="hibernate.c3p0.min_size">$dbServerB{hibernate.c3p0.max_size}</prop>
        <prop key="hibernate.c3p0.timeout">$dbServerB{hibernate.c3p0.timeout}</prop>
        <prop key="hibernate.c3p0.max_statements">$dbServerB{hibernate.c3p0.max_statements}</prop>
        <prop key="hibernate.show_sql">$dbServerB{hibernate.show_sql}</prop>
        <prop key="hibernate.format_sql">$dbServerB{hibernate.format_sql}</prop>
<!--    <prop key="hibernate.transaction.factory_class">org.hibernate.transaction.CMTTransactionFactory</prop>  -->
        <prop key="hibernate.transaction.factory_class">com.atomikos.icatch.jta.hibernate3.AtomikosJTATransactionFactory</prop>
        <prop key="hibernate.transaction.manager_lookup_class">com.atomikos.icatch.jta.hibernate3.TransactionManagerLookup</prop>
        <prop key="hibernate.current_session_context_class">org.hibernate.context.JTASessionContext</prop>
      </props>
    </property>
    <property name="annotatedClasses">
      <set>
        <value>vdms.model.State</value>
      </set>
    </property>
  </bean>
 
  <bean id="txProxyB"
    class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
    abstract="true">
    <property name="transactionManager" ref="jtaTxManager" />
    <property name="transactionAttributeSource">
      <bean class="org.springframework.transaction.annotation.AnnotationTransactionAttributeSource" />
    </property>
  </bean>

  <tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/>
  <tx:jta-transaction-manager />

  <bean id="stateDAO"                    parent="txProxyB">
    <property name="target">
      <bean class="vdms.dao.hibernate.StateDAOHibernate">
        <property name="sessionFactory" ref="sessionFactoryB" />
      </bean>
    </property>
  </bean>

</beans> 
[/code]

and my simple app
TestQueries
[code]
package tule.model;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.*;

import org.apache.log4j.*;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.orm.hibernate3.SessionFactoryUtils;
import org.springframework.orm.hibernate3.SessionHolder;
import org.springframework.transaction.support.TransactionSynchronizationManager;

import utils.*;

import tule.dao.*;
import tule.dao.hibernate.*;
import tule.model.*;

public class TestQueries
{
    StateDAO  stateDAO  = null;

    State    currState = null;
   
    SessionFactory sfB;
    Session      sessB;

    public static void main(String[] args)
    {
        logger.debug("entering");
        System.out.println("starting");

        String inn_str, tmp_str, roww;
        ArrayList<String> error_list;

        TestQueries theApp;
        System.out.println("at A");

        theApp = new TestQueries();
        System.out.println("at B");
       
        try {
            ApplicationContext ctx = new ClassPathXmlApplicationContext("ApplicationContext.xml");
            System.out.println("at C");

            theApp.stateDAO    = (StateDAO)    ctx.getBean("stateDAO");
            System.out.println("at D");
           
            theApp.sfB = (SessionFactory) ctx.getBean("sessionFactoryB", SessionFactory.class);
            theApp.sessB = SessionFactoryUtils.getSession(  theApp.sfB, true);
            TransactionSynchronizationManager.bindResource( theApp.sfB, new SessionHolder( theApp.sessB));
            System.out.println("at E");
           
            List<State> states = theApp.stateDAO.getAll();
            for( State st : states) {
                System.out.println( st.toString());
            }
           
            TransactionSynchronizationManager.unbindResource( theApp.sfB);
            theApp.sessB.close();
            theApp.sfB.close();
           
            System.out.println("finished");
            logger.debug("exiting");
        } catch ( Error e) {
            System.out.println("OOPS, had an error");
            logger.debug("exiting");
            e.printStackTrace();
            System.exit(-4);
        }
    }
}
[/code]

Problem is when I execute TestQueries I never get to point C -
when I use this in configuring my sessionfactory
[code]
<!--    <prop key="hibernate.transaction.factory_class">org.hibernate.transaction.CMTTransactionFactory</prop>  -->
[/code]
I get this
[code]
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Invocation of init method failed; nested exception is java.lang.IllegalStateException: No JTA UserTransaction available - specify either 'userTransaction' or 'userTransactionName' or 'transactionManager' or 'transactionManagerName'
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1455)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
    at tule.model.TestQueries.main(TestQueries.java:84)
Caused by: java.lang.IllegalStateException: No JTA UserTransaction available - specify either 'userTransaction' or 'userTransactionName' or 'transactionManager' or 'transactionManagerName'
    at org.springframework.transaction.jta.JtaTransactionManager.checkUserTransactionAndTransactionManager(JtaTransactionManager.java:474)
    at org.springframework.transaction.jta.JtaTransactionManager.afterPropertiesSet(JtaTransactionManager.java:414)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)
    ... 12 more
[/code]

but when I use this in configuring my sessionfactory
[code]
        <prop key="hibernate.transaction.factory_class">com.atomikos.icatch.jta.hibernate3.AtomikosJTATransactionFactory</prop>
[/code]
I get a NPE
[code]
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactoryB' defined in class path resource [ApplicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NullPointerException
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1455)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:567)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
    at vdms.model.TestQueries.main(TestQueries.java:84)
Caused by: java.lang.NullPointerException
    at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:159)
    at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2163)
    at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2159)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1383)
    at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:954)
    at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:860)
    at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:779)
    at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:188)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)
    ... 12 more
[/code]

My project does have visibility to com.atomikos.icatch.jta.hibernate3.AtomikosJTATransactionFactory, meaning I
can "import com.atomikos.icatch.jta.hibernate3.*;" and I do see AtomikosJTATransactionFactory appear in the list
of classes available;

I can't figure out why I'm getting these errmsgs, my beans for transactionManager and its properties look ok.
the pom excludes a few transitive dependencies that cause conflicts.

Can anyone spot what's wrong/missing/extraneous? It must be something fiendishly subtle. Sure could use some help
getting this going.

TIA,


Still-learning Steve
kerchunk Send private email
Thursday, May 31, 2012
 
 
addendum--

for reasons unknown this property in the sessionFactory bean was causing the NPE at runtime:

<property name="useTransactionAwareDataSource" value="true" />

then I stumbled into the issue of not having any xaProperties set in my dataSource bean causes that bean to silently fail. So I added in the standard three properties (and removed them from the sessionFactory properties) like so:

  <bean id="dataSourceServerB" class="com.atomikos.jdbc.AtomikosDataSourceBean" init-method="init" destroy-method="close">
    <property name="uniqueResourceName"><value>XADBMS</value></property>
    <property name="xaDataSourceClassName"><value>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</value></property>
    <property name="xaProperties">
        <props>
            <prop key="URL">$dbServerB{hibernate.connection.url}</prop>
            <prop key="user">$dbServerB{hibernate.connection.username}</prop>
            <prop key="password">$dbServerB{hibernate.connection.password}</prop>
        </props>
    </property>
    <property name="poolSize"><value>5</value></property>
  </bean>

  <!-- Hibernate session factory -->
  <bean id="sessionFactoryB"
    class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<!--<property name="useTransactionAwareDataSource" value="true" />  this causes an NPE -->
    <property name="dataSource"        ref="dataSourceServerB" />
    <property name="hibernateProperties">
      <props>
        <prop key="hibernate.dialect">$dbServerB{hibernate.dialect}</prop>
        <prop key="hibernate.connection.characterEncoding">$dbServerB{hibernate.connection.characterEncoding}</prop>
        <prop key="hibernate.connection.driver_class">$dbServerB{hibernate.connection.driver_class}</prop>
<!--    <prop key="hibernate.connection.url">$dbServerB{hibernate.connection.url}</prop>
        <prop key="hibernate.connection.username">$dbServerB{hibernate.connection.username}</prop>
        <prop key="hibernate.connection.password">$dbServerB{hibernate.connection.password}</prop>  -->
        <prop key="hibernate.connection.release_mode">$dbServerB{hibernate.connection.release_mode}</prop>
        <prop key="hibernate.cache.provider_class">$dbServerB{hibernate.cache.provider_class}</prop>
        <prop key="hibernate.c3p0.min_size">$dbServerB{hibernate.c3p0.min_size}</prop>
        <prop key="hibernate.c3p0.min_size">$dbServerB{hibernate.c3p0.max_size}</prop>
        <prop key="hibernate.c3p0.timeout">$dbServerB{hibernate.c3p0.timeout}</prop>
        <prop key="hibernate.c3p0.max_statements">$dbServerB{hibernate.c3p0.max_statements}</prop>
        <prop key="hibernate.show_sql">$dbServerB{hibernate.show_sql}</prop>
        <prop key="hibernate.format_sql">$dbServerB{hibernate.format_sql}</prop>
        <prop key="hibernate.hbm2ddl.auto">$dbServerB{hibernate.hbm2ddl.auto}</prop>
    <prop key="hibernate.transaction.factory_class">org.hibernate.transaction.CMTTransactionFactory</prop>
 <!-- <prop key="hibernate.transaction.factory_class">com.atomikos.icatch.jta.hibernate3.AtomikosJTATransactionFactory</prop>  -->
        <prop key="hibernate.transaction.manager_lookup_class">com.atomikos.icatch.jta.hibernate3.TransactionManagerLookup</prop>
        <prop key="hibernate.current_session_context_class">org.hibernate.context.JTASessionContext</prop>
      </props>
    </property>
    <property name="annotatedClasses">
      <set>
        <value>tule.model.State</value>
      </set>
    </property>
  </bean>

but it doesn't like the password being blank, as in the case of using the default root:<blank>  as with MySQL

So I'm on the home-stretch ... anyone know of way around this?

TIA

Still-learning Steve
kerchunk Send private email
Friday, June 01, 2012
 
 
Finally got my app working after upgrading my mysql connector from 5.1.6 to 5.1.8 ( googling turned up one single post related to this, and that post was from this very forum!)

And for those who follow, "Pro Spring 3" by Apress , published 2012/04 , chapter 13 , lays it all out with a Atomikos/JTA/JPA2 example. Wished I'd found that book sooner!

Regards,

Still-learing Steve
kerchunk Send private email
Saturday, June 02, 2012
 
 

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics