2 Replies Latest reply on Dec 20, 2002 11:49 AM by juhalindfors

    Problem with UserTransaction

    maramonar

      Hello to all.
      I am having a problem with the use of UserTransaction to delimit one transaccion where several updates are made.
      My environment is jBoss 3.0.0+Jetty and SQL2000 with MS JDBC driver.
      The problem that I have is that when commit() the transaction the tables updated are blocked for reading,
      and when I stop JBOSS, this does rollback of all the updates made by transaction.
      It seems that commit() is not executed in fact.
      Somebody can say to me if I am making something in erronea form?
      Mi code is:
      public void create(Object object) throws SaveException {
      JdbcPersistenceManager pm = (JdbcPersistenceManager)this.getPersistenceManager();
      Connection conn = pm.getConnectionProvider().getConnection();
      UserTransaction tx = null;
      try {
      tx = (UserTransaction)ObjectLocator.getInstance().lookup("java:comp/UserTransaction");
      tx.begin();
      XmlHandler handler = new XmlHandler((String)object);
      String whenSpecID = "";
      String sql = this.getSQLforWhenSpec(handler);
      Statement stInsert = conn.createStatement();
      stInsert.executeUpdate(sql);
      Statement stQuery = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
      ResultSet rs = stQuery.executeQuery("SELECT @@identity whenSpecID");
      if (rs.next()) {
      whenSpecID = rs.getString("whenSpecID");
      }
      rs.close();
      sql = this.getSQLforTriggers(handler, whenSpecID);
      stInsert.executeUpdate(sql);
      tx.commit();
      } catch (Exception e) {
      try {
      if (tx != null) {
      tx.rollback();
      }
      } catch (Exception se) {
      throw new SaveException("TriggerSaveStrategy:create()",e);
      }
      throw new SaveException("TriggerSaveStrategy:create()",e);
      } finally {
      try {
      if (conn != null) {
      conn.close();
      }
      } catch (Exception e) {
      e.printStackTrace();
      }
      }
      }

      PS: if i use JDBC transaction (ie. conn.setAutocommit(false);....conn.commit()...conn.setAutocommit(true))
      everything run fine.

        • 1. Re: Problem with UserTransaction
          crazy_deba

          Hi All,
          I have tried both the Container Managed Txn and Bean managed txn with the Same setup(sqlserver 2000 and JBOSS3.0) for a session bean and out of around 50 calls and Prepared statements 3 are locking .But the entity beans are working properly with transaction. Is it mandatory to use Session Synchronisation interface ?????
          I have tried with java.sql and for the same table it works fine form my code.

          • 2. Re: Problem with UserTransaction

            Where is that JDBC persistence manager coming from? Why are you not looking up JBoss datasources from the JNDI?