Atomikos Forum |
|
my application environment is: tomcat + spring + hibernate. I want to use jta/xa to manage to dbms(mysql and oracle). my spring's xml is below:
<bean id="atomikosTransactionManager" class="com.atomikos.icatch.jta.UserTransactionManager" init-method="init" destroy-method="close"> <property name="forceShutdown"><value>true</value></property> </bean> <bean id="atomikosUserTransaction" class="com.atomikos.icatch.jta.UserTransactionImp"> <property name="transactionTimeout"><value>300</value></property> </bean> <bean id="springTransactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"> <property name="transactionManager"><ref bean="atomikosTransactionManager" /></property> <property name="userTransaction"><ref bean="atomikosUserTransaction" /></property> </bean> <tx:annotation-driven transaction-manager="springTransactionManager"/> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource" ref="myDataSource"/> <property name="packagesToScan" value="com.kevin.statistic.entity"/> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect"> org.hibernate.dialect.MySQLDialect </prop> <prop key="hibernate.connection.isolation">3</prop> <prop key="hibernate.current_session_context_class">jta</prop> <prop key="hibernate.transaction.factory_class"> org.hibernate.transaction.JTATransactionFactory </prop> <prop key="hibernate.transaction.manager_lookup_class"> com.atomikos.icatch.jta.hibernate3.TransactionManagerLookup </prop> </props> </property> </bean> <bean id="myDataSource" class="com.atomikos.jdbc.AtomikosDataSourceBean"> <property name="uniqueResourceName"><value>MYSQL</value></property> <property name="xaDataSourceClassName"><value>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</value></property> <property name="xaProperties"> <props> <prop key="user">root</prop> <prop key="password">root</prop> <prop key="url">jdbc:mysql://192.168.1.101:3306/statistic</prop> </props> </property> <property name="poolSize"><value>4</value></property> <property name="borrowConnectionTimeout"><value>60</value></property> </bean> <bean id="oracleSessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource" ref="oracleDataSource"/> <property name="packagesToScan" value="com.kevin.statistic.oracleentity"/> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect"> org.hibernate.dialect.Oracle10gDialect </prop> <prop key="hibernate.connection.isolation">3</prop> <prop key="hibernate.current_session_context_class">jta</prop> <prop key="hibernate.transaction.factory_class"> org.hibernate.transaction.JTATransactionFactory </prop> <prop key="hibernate.transaction.manager_lookup_class"> com.atomikos.icatch.jta.hibernate3.TransactionManagerLookup </prop> </props> </property> </bean> <bean id="oracleDataSource" class="com.atomikos.jdbc.AtomikosDataSourceBean"> <property name="uniqueResourceName"><value>ORACLE</value></property> <property name="xaDataSourceClassName"><value>oracle.jdbc.xa.client.OracleXADataSource</value></property> <property name="xaProperties"> <props> <prop key="user">kevin</prop> <prop key="password">asdfff</prop> <prop key="url">jdbc:oracle:thin:@192.168.1.101:1521:XE</prop> </props> </property> <property name="poolSize"><value>4</value></property> <property name="borrowConnectionTimeout"><value>60</value></property> </bean> <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate"> <property name="sessionFactory"><ref bean="oracleSessionFactory"/></property> </bean> When I call:"oracleHibernateTemplate.getSessionFactory().getCurrentSession()", There throws exception:org.hibernate.HibernateException: Unable to locate current JTA transaction. Are there any thing wrong in my configuration? I dealing this problem for a long time. Thanks!
Which hibernate version do you use?
If it is a rather actual one please read the atomikos wiki or the hibernate docs - you are using the wrong jta tx factory_class, you should use no factory at all with modern version, only the tx lookup is needed. http://docs.jboss.org/hibernate/stable/entitymanager/reference/en/html/transactions.html#transactions-demarcation-jta |