Hi,
I need to get data from two databases. Therefore I structure my program as follows:
Code:
public Object getDB1and2Data()
throws HibernateException {
Session sess = null;
Transaction tran = null;
try {
sess = GblUtils.getDB1Session();
tran = sess.beginTransaction();
try {
// ... here I get some data from DB1
// and then some from DB2
Object obj = getDB2Data(obj1);
tran.commit();
}
catch (HibernateException x) {
if (tran!=null) tran.rollback();
throw x;
}
finally {sess.close();}
}
catch (HibernateException x) {
x.printStackTrace();
throw x;
}
return ...;
}
public Object getDB2Data(Object par)
throws HibernateException {
Session sess = GblUtils.getDB2Session();
Transaction tran = sess.beginTransaction();
try {
// ... here I get the data from DB2
tran.commit();
}
catch (HibernateException x) {
if (tran!=null) tran.rollback();
throw x;
}
finally {sess.close();}
return ...;
}
When I execute getDB1and2Data() everything is fine. However, after a while (2 mins) I get the following stack trace in the JBoss (3.2.3) console:
Quote:
07:02:21,406 WARN [TransactionImpl] Transaction TransactionImpl:XidImpl [Format
Id=257, GlobalId=zarathustra//1, BranchQual=] timed out. status=STATUS_ACTIVE
07:02:21,406 ERROR [ThreadPool] Unexpected exception
java.lang.InterruptedException
at java.lang.Object.wait(Native Method)
at java.lang.Object.wait(Object.java:426)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:653)
at java.lang.Thread.run(Thread.java:536)
What is wrong? I feel it's the nested transactions. How would I structure my program then?
Thanks,
Vladimir