|
|
Hi, I am using jencks + tranql to do local tests of a JTA environment. When I deal with only plain jdbc and jms everything works fine, I can make distributed transactions (commit and rollback) but when I try to use Hibernate, I have this strange errors:
WARN Transaction - Unable to enlist XAResource org.apache.geronimo.transaction.manager.WrapperNam edXAResource@2aff693e, errorCode: -3oracle.jdbc.xa.OracleXAException
at oracle.jdbc.xa.OracleXAResource.checkError(OracleX AResource.java:1190)
at oracle.jdbc.xa.client.OracleXAResource.start(Oracl eXAResource.java:311)
at org.apache.geronimo.transaction.manager.WrapperNam edXAResource.start(WrapperNamedXAResource.java:86)
at org.apache.geronimo.transaction.manager.Transactio nImpl.enlistResource(TransactionImpl.java:173)
at org.apache.geronimo.transaction.context.Inheritabl eTransactionContext.enlistResource(InheritableTran sactionContext.java:92)
at org.apache.geronimo.connector.outbound.Transaction EnlistingInterceptor.getConnection(TransactionEnli stingInterceptor.java:53)
at org.apache.geronimo.connector.outbound.Transaction CachingInterceptor.getConnection(TransactionCachin gInterceptor.java:81)
at org.apache.geronimo.connector.outbound.ConnectionH andleInterceptor.getConnection(ConnectionHandleInt erceptor.java:43)
at org.apache.geronimo.connector.outbound.TCCLInterce ptor.getConnection(TCCLInterceptor.java:39)
at org.apache.geronimo.connector.outbound.AbstractCon nectionManager.allocateConnection(AbstractConnecti onManager.java:61)
at org.tranql.connector.jdbc.DataSource.getConnection (DataSource.java:56)
at org..orm.hibernate3.LocalDataSource ConnectionProvider.getConnection(LocalDataSourceCo nnectionProvider.java:81)
and then:
Caused by: java.sql.SQLException: ORA-02089: COMMIT is not allowed in a subordinate session
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBE rror.java:134)
at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:2 89)
at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:582)
at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol .java:1986)
at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteDescribe (TTC7Protocol.java:880)
at oracle.jdbc.driver.OracleStatement.doExecuteQuery( OracleStatement.java:2516)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTi meout(OracleStatement.java:2850)
at oracle.jdbc.driver.OraclePreparedStatement.execute Update(OraclePreparedStatement.java:609)
at oracle.jdbc.driver.OraclePreparedStatement.execute Query(OraclePreparedStatement.java:537)
at org.tranql.connector.jdbc.PreparedStatementHandle. executeQuery(PreparedStatementHandle.java:49)Is seems that quot;org..orm.hibernate3.LocalSessionFa ctoryBeanquot;
that is used to create my hibernate session factory somehow loose control
of the transaction/connection. Any clues?
Here is my configuration:
--------------------------------------------------------------------------
lt;?xml version=quot;1.0quot; encoding=quot;UTF-8quot;?gt;
lt;!DOCTYPE beans PUBLIC quot;-//SPRING//DTD BEAN//ENquot; quot;dtd/spring-beans.dtdquot;gt;
lt;beansgt;
lt;bean id=quot;transactionContextManagerquot; class=quot;org.jencks.factory.TransactionContextManage rFactoryBeanquot;/gt;
lt;bean id=quot;userTransactionquot; class=quot;org.jencks.factory.GeronimoTransactionManag erFactoryBeanquot;/gt;
lt;bean id=quot;transactionManagerquot; class=quot;org..transaction.jta.JtaTran sactionManagerquot;gt;
lt;property name=quot;userTransactionquot; ref=quot;userTransactionquot;/gt;
lt;/beangt;lt;bean id=quot;mySessionFactoryquot; class=quot;org..orm.hibernate3.LocalSes sionFactoryBeanquot; lazy-init=quot;truequot;gt;
lt;property name=quot;mappingResourcesquot;gt;
lt;listgt;
lt;valuegt;queries.hbm.xmllt;/valuegt;
lt;/listgt;
lt;/propertygt;
lt;property name=quot;hibernatePropertiesquot;gt;
lt;propsgt;
lt;prop key=quot;hibernate.dialectquot;gt;
org.hibernate.dialect.Oracle9Dialect
lt;/propgt;
lt;prop key=quot;hibernate.show_sqlquot;gt;truelt;/propgt;
lt;prop key=quot;hibernate.cache.use_query_cachequot;gt;truelt;/propgt;
lt;prop key=quot;hibernate.jdbc.fetch_sizequot;gt;200lt;/propgt;
lt;prop key=quot;hibernate.cache.provider_classquot;gt;
org.hibernate.cache.EhCacheProvider
lt;/propgt;
lt;prop key=quot;hibernate.cglib.use_reflection_optimizerquot;gt;
true
lt;/propgt;
lt;/propsgt;
lt;/propertygt;
lt;property name=quot;dataSourcequot;gt;
lt;ref bean=quot;dataSourcequot;/gt;
lt;/propertygt;
lt;/beangt;lt;bean id=quot;transactionSupportquot; class=quot;org.jencks.factory.XATransactionFactoryBean quot;gt;
lt;property name=quot;useTransactionCachingquot;gt;
lt;valuegt;truelt;/valuegt;
lt;/propertygt;
lt;property name=quot;useThreadCachingquot;gt;
lt;valuegt;falselt;/valuegt;
lt;/propertygt;
lt;/beangt;lt;bean id=quot;poolingSupportquot; class=quot;org.jencks.factory.SinglePoolFactoryBeanquot;gt;
lt;property name=quot;maxSizequot;gt;
lt;valuegt;2lt;/valuegt;
lt;/propertygt;
lt;property name=quot;minSizequot;gt;
lt;valuegt;1lt;/valuegt;
lt;/propertygt;
lt;property name=quot;blockingTimeoutMillisecondsquot;gt;
lt;valuegt;60lt;/valuegt;
lt;/propertygt;
lt;property name=quot;idleTimeoutMinutesquot;gt;
lt;valuegt;60lt;/valuegt;
lt;/propertygt;
lt;property name=quot;matchOnequot;gt;
lt;valuegt;truelt;/valuegt;
lt;/propertygt;
lt;property name=quot;matchAllquot;gt;
lt;valuegt;truelt;/valuegt;
lt;/propertygt;
lt;property name=quot;selectOneAssumeMatchquot;gt;
lt;valuegt;truelt;/valuegt;
lt;/propertygt;
lt;/beangt;
lt;bean id=quot;connectionManagerquot; class=quot;org.jencks.factory.ConnectionManagerFactory Beanquot;gt;
lt;property name=quot;transactionSupportquot;gt;
lt;ref local=quot;transactionSupportquot;/gt;
lt;/propertygt;
lt;property name=quot;poolingSupportquot;gt;
lt;ref local=quot;poolingSupportquot;/gt;
lt;/propertygt;
lt;/beangt;
lt;!-- Interceptor de transacao --gt;
lt;bean id=quot;transInterceptquot; class=quot;org..transaction.interceptor .TransactionInterceptorquot;gt;
lt;property name=quot;transactionManagerquot;gt;
lt;ref bean=quot;transactionManagerquot;/gt;
lt;/propertygt;
lt;property name=quot;transactionAttributesquot;gt;
lt;propsgt;
lt;prop key=quot;*quot;gt ROPAGATION_REQUIRES_NEW,-Exceptionlt;/propgt;
lt;/propsgt;
lt;/propertygt;
lt;/beangt;
lt;bean id=quot;dataSourcequot; class=quot;org..jca.support.LocalConnec tionFactoryBeanquot;gt;
lt;property name=quot;managedConnectionFactoryquot;gt;
lt;ref bean=quot;tranqlManagedConnectionFactoryquot;/gt;
lt;/propertygt;
lt;property name=quot;connectionManagerquot;gt;
lt;ref bean=quot;connectionManagerquot;/gt;
lt;/propertygt;
lt;/beangt;
lt;bean id=quot;tranqlManagedConnectionFactoryquot; class=quot;org.tranql.connector.oracle.XAMCFquot;gt;
lt;property name=quot;driverTypequot; value=quot;thinquot;/gt;
lt;property name=quot;serverNamequot; value=quot;hostquot;/gt;
lt;property name=quot;portNumberquot; value=quot;portquot;/gt;
lt;property name=quot;serviceNamequot; value=quot;intquot;/gt;
lt;property name=quot;userNamequot; value=quot;userquot;/gt;
lt;property name=quot;passwordquot; value=quot;pasquot;/gt;
lt;/beangt;
lt;bean id=quot;connectionFactoryquot; class=quot;org..jca.support.LocalConnec tionFactoryBeanquot;gt;
lt;property name=quot;managedConnectionFactoryquot;gt;
lt;ref local=quot;jmsManagedConnectionFactoryquot;/gt;
lt;/propertygt;
lt;property name=quot;connectionManagerquot;gt;
lt;ref local=quot;connectionManagerquot;/gt;
lt;/propertygt;
lt;/beangt;
lt;/beansgt;
--------------------------------------------------------------------------TIA,
Kingston
You should set on the Hibernate SessionFactoryBean the jtaTransactionManager to use - check out the javadocs for more info.
Were you able to resolve this issue ? any guidance ? I have the same exact problem but with JBoss. When I switch from HibernateTM to JTA it gives this
COMMIT is not allowed in a subordinate session
error! any ideas ? When I try to set quot;jtaTransactionManagerquot; on the HibernateSessionFactory, it complains about converting from Spring's JTATM to javax TransactionManager
Help
Thanks
Fadi
error! any ideas ? When I try to set quot;jtaTransactionManagerquot; on the HibernateSessionFactory, it complains about converting from Spring's JTATM to javax TransactionManager
HibernateTM is a PlatformTransactionManager while Hibernate SessionFactory requiers a javax.TM - you need to do a conversion between them by calling getTransactionManager on the JtaTM. See the javadocs for more info.Code:
lt;bean id=quot;jtaTMquot; class=quot;org..transaction.jta.JtaTransactionManagerquot;gt;
...
lt;/beangt;
lt;bean id=quot;sessionFactoryquot; class=quot;org..hibernate3.LocalSessionFactoryBeanquot;gt;
...
lt;property name=quot;jtaTransactionManagergt; lt;bean factory-bean=quot;jtaTMquot; factory-method=quot;getTransactionManagerquot;/gt;
lt;/propertygt;
...
lt;/beangt;
Originally Posted by Costin LeauYou should set on the Hibernate SessionFactoryBean the jtaTransactionManager to use.
In which cases/When do I need to set this jtaTransactionManager explicitely? I don't do this and it seems to work. My setup looks very similar to Kingston's.
Regards,
Jörg
If you want to use JTA/global transactions then you should set it - if not then rely on the local transactions through HibernateTransactionManager.
That does not really answer my question
From what I see Hibernate does not handle any transactions - with or without injecting the TransactionManager. In fact, Hibernate also creates a JDBCTransactionFactory when having the TransactionManager injected, but it won't be used in both cases.
That was why I wanted to know why Hibernate needs the TransactionManager when it does not really care about transactions. Where could my setup fail without injecting TransactionManager into the SessionFactory?
Jörg
From what I see Hibernate does not handle any transactions - with or without injecting the TransactionManager.
I think I lost you here - Hibernate does handle local transactions. What you want is global transactions, in which case, Hibernate delegates everything to the JtaTM.
Hibernate doesn't require a transaction manager - in fact, when dealing with transactions one defines an additional HibernateTransactionManager which requires a SessionFactory. However, while supplemental, the TM uses internally the Hibernate API for committing/rolling back transactions.
What I just observed is the usage of JDBCTransactionFactory - with or without injecting a TM. But what is never done is the actual call to createTransaction(..) of it. That's why I assumed Hibernate does not handle any transactions. What I understand from what you wrote is that it handles transaction on plain JDBC level as fallback.
Now I only wonder why exactly the same happens when injecting a TM - and if my set up is correct at all The only difference I saw is in org..orm.hibernate3.SpringSessionSy nchronization, but not in Hibernate itself. Nothing else retrieves the TM from the SessionFactory.
Jörg |
|