-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: nested transactions?
PostPosted: Sat Mar 19, 2005 9:02 am 
Newbie

Joined: Thu Feb 03, 2005 11:40 pm
Posts: 8
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


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 21, 2005 11:44 am 
Newbie

Joined: Thu Feb 03, 2005 11:40 pm
Posts: 8
I looked more carefully at the log and noticed (in other spots) warnings from JBoss:

Quote:
WARN [SessionImpl] afterTransactionCompletion() was never called


and in a different spot

Quote:
WARN [TxConnectionManager] Prepare called on a local tx. Use of local transactions on a local transaction with more than one branch may result in inconsistent data in some cases of failure.


I's just using the Hibernate transaction API as recommended in the Hibernate documentation.

Am I missing something?

Thanks,
Vladimir


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.