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 10.2.0.2). 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":
Code:
<server>
<mbean code="org.hibernate.jmx.HibernateService" name="jboss.jca:service=HibernateFactory,name=XATestNode2HibernateSessionFactory">
<attribute name="Datasource">
java:jdbc/XATestNode2_DS
</attribute>
<!-- Bind the Hibernate service to JNDI -->
<attribute name="JndiName">
XATestNode2HibernateSessionFactory
</attribute>
<!-- Transaction integration -->
<attribute name="TransactionStrategy">
org.hibernate.transaction.CMTTransactionFactory
</attribute>
<attribute name="TransactionManagerLookupStrategy">
org.hibernate.transaction.JBossTransactionManagerLookup
</attribute>
<attribute name="FlushBeforeCompletionEnabled">true</attribute>
<attribute name="AutoCloseSessionEnabled">true</attribute>
<attribute name="Dialect">
org.hibernate.dialect.Oracle9Dialect
</attribute>
<attribute name="SecondLevelCacheEnabled">false</attribute>
<attribute name="CacheProviderClass">
org.hibernate.cache.NoCacheProvider
</attribute>
<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">
de/lbank/xatestnode2/hibernate/Node2TestData.hbm.xml
</attribute>
</mbean>
</server>
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;-)
Thanks
Jochen