0 Replies Latest reply on Jan 11, 2007 11:04 AM by j_ri

    distributed transaction in jboss cluster with hibernate


      I'd like ti continue my thread (http://www.jboss.com/index.html?module=bb&op=viewtopic&t=98301) from the JBossTransactions forum here, since now I think it's a problem with my Hibernate configuration for my JBoss.

      After Reading a lot within the Forums here and at jboss.org I finally ask the question here in this forum.

      I have an issue using hibernate in a clustered JBoss environment (JBoss 4.0.5GA, JBossTS JTS 4.2.2GA, Oracle 10g with Driver I have two cluster nodes and each node has running a stateless session bean.

      1.) node1 inserts data to datasource1
      2.) node1 calls node2
      3.) node2 (should) read the data persisted by node1
      4.) node2 inserts data to datasource2

      Unfortunately this scenario doesn't work. In step 3 the ejb on node2 is not able to read the data which was written by the ejb on node1;-(
      There is no Exception; the reading from the datasource works...there's just an empty result.

      To get this to work I tried the following Hibernate configuration:
      The .ear file on node1 defines one SessionFactoryMBean pointing to datasource1.
      The .ear file on node2 defines 2 SessionFactoryMBeans; one pointing to datsource1 for reading the data written by ejb1 and another pointing to datasource2 for persisting other data.
      The datasources point to different schemas on the same Oracle database.

      2-Phase-Commit between the two datasources works (both ejb can write their data, just the read bewteen returns nothing), but it's not a real distributed transaction.

      My cluster and JBossTS setup should be correct. I created the same example using plain jdbc via the jndi-looked-up-datasources...and this works perfectly as expected.

      I deployed Hibernate as a .sar file within the .ear as described in the Hibernate-3.2.0 documentation Chapter 3.8.4.
      And I tried with "org.hibernate.transaction.CMTTransactionFactory" and "org.hibernate.transaction.JTATransactionFactory":

       <mbean code="org.hibernate.jmx.HibernateService" name="jboss.jca:service=HibernateFactory,name=XATestNode2HibernateSessionFactory">
       <attribute name="Datasource">
       <!-- Bind the Hibernate service to JNDI -->
       <attribute name="JndiName">
       <!-- Transaction integration -->
       <attribute name="TransactionStrategy">
       <attribute name="TransactionManagerLookupStrategy">
       <attribute name="FlushBeforeCompletionEnabled">true</attribute>
       <attribute name="AutoCloseSessionEnabled">true</attribute>
       <attribute name="Dialect">
       <attribute name="SecondLevelCacheEnabled">false</attribute>
       <attribute name="CacheProviderClass">
       <attribute name="QueryCacheEnabled">false</attribute>
       <attribute name="JdbcFetchSize">20</attribute>
       <attribute name="BatchVersionedDataEnabled">false</attribute>
       <!-- <attribute name="StreamsForBinaryEnabled">true</attribute> -->
       <attribute name="JdbcBatchSize">20</attribute>
       <attribute name="ShowSqlEnabled">true</attribute>
       <!-- Mapping files -->
       <attribute name="MapResources">

      In my code I use "sessionFactory.getCurrentSession().persist(xxx)" to get my session.
      As datasource I use a XA-Datasource with the Oracle thin driver (which works well in my plain jdbc example)

      Are two SessionFactories (on different Cluster Nodes) not able to return sessions for the same distributed transaction? Or is there a mistake in my configuration?

      After three days of reading and testing I feel quite frustrated. So help would be very much appreciated;-)