1 Reply Latest reply on Jan 30, 2006 8:32 AM by jbaiju

    Basic question in Usertransaction

    jbaiju

      Hi,

      I have a basic question with user transaction.

      My Issue:

      I am using EJB (Stateless bean) in one method i am calling UserTransaction.begin() and after some JDBC calls i am commiting the transaction ut.commit(); in the next line i am passing the UserTransaction object to another Java Class there i need to execute a batch in a loop. So every iteration of the loop i am calling the transaction.begin() and i am creating connection and execute three JDBC calls by getting three connection. At the end of the loop i am calling transation.commit().

      while(batch.hasNext())
      {
      transaction.begin();
      try
      {
      Connection con = dataSource.getConnection();
      con.execute(query);
      Connection con1 = dataSource.getConnection();
      con1.execute(query1);
      Connection con2 = dataSource.getConnection();
      con2.execute(query2);
      transaction.commit();
      }catch(exception e)
      {
      transaction.rollBack();
      }
      finally
      {
      con.close();
      con1.close();
      con2.close();
      }
      }

      While monitoring the pool status in the jmx-console in jboss for each iteration there is only one connection is taken from the pool and after the execution of the finally statement no connection is returned to the pool till the end of the loop.

      My understanding with the UerTansaction is transaction is live between the begin and commit method of the user transaction, but it behaves like the transaction is live for the whole loop.

      Please advice me what i am doing wrong.