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

    Problem with UserTransaction

    Mauro Ramon Newbie

      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.