3 Replies Latest reply on Sep 16, 2003 8:57 AM by n2

    CMT, my rollback doesn't seem to be working

    alen

      I was hopping someone could maybe help me solve a problem with regards to JBoss
      application server.
      Here it goes...

      I'm using JBoss 3.2.1 at this stage and am trying to make use of the JBossTX
      for handling managed transactions.

      Scenario:

      I have deployed a Stateless Session Bean (using CMT with */Required) that
      has a method named createPerson(...).
      This method manipulates a DTO and passes it on to my underlying persistence
      manager that stores the person's info into the underlying datastore. My
      datastore is a MySQL 3.x DB and I'm using a MySQL Connector/J 3.0.7 Stable
      driver.

      Session bean code snippet
      ----------------------------------

      public void createPerson(Person p) {
      Session s = null;
      try {
      Context ctx = new InitialContext();
      SessionFactory factory =
      (SessionFactory) ctx.lookup("java:/hibernate/HibernateFactory");

      s = factory.openSession();

      s.save(p);
      //s.flush();

      if (1==1) {
      //sessionContext.setRollbackOnly();
      throw new Exception("JTS test...");
      }
      } catch(Exception e) {
      e.printStackTrace();
      // this throw should automatically perform a rollback
      throw new EJBException(
      "Transaction failed: " + e.getMessage());
      } finally {
      if(s!=null) try { s.close(); } catch(Exception e) {}
      }
      }

      Now as you can see above, I throw an Exception that rethrows a system-level
      exception named EJBException.
      In this case, Container should automatically rollback the running
      transaction.
      However my database shows that INSERT statement has been committed as it
      reflects the inserted change.

      Alternatively, I have tried to set the ROLLBACK-ONLY using the session
      context's
      setRollbackOnly method and then throw an application-level exception.
      Unfortunately this didn't work either.

      My transaction-service.xml is running with default settings.
      And I'm running a service for MySQL datasource using the
      local-tx-datasource:

      mysql-ds.xml
      --------------------


      <local-tx-datasource>
      <jndi-name>jdbc/ejbPool</jndi-name>
      <connection-url>jdbc:mysql://localhost:3306/MyDB</connection-url>
      <driver-class>com.mysql.jdbc.Driver</driver-class>
      <user-name></user-name>

      </local-tx-datasource>


      Do I perhaps require to use the XA protocol for some reason?

      Any suggestions or ideas that I can try to help me find the solution to my
      problem, much appreciated.
      Maybe a way in which I can monitor the JBossTX invoking the begins, commits
      and rollbacks on my methods?

        • 1. Re: CMT, my rollback doesn't seem to be working
          n2

          I have the same problem and no solution.

          i check the connnection in the hibernate session by session.connection().getAutoCommit(). the result was true. so i set it to false. then in case of exception no statement was commited but there was a blocking prozess on the database-server.

          if getAutoCommit() is true transaction-management cant work...

          • 2. Re: CMT, my rollback doesn't seem to be working
            raja05

            Try out MySQL 4 , or set the INNODB true in MySQL3.x
            I believe there was a note in the MySQL site about transaction management enabled in MySQL 4 or above and a patch for 3.x to set the INNODB.

            I think this is more of a MySQL Tx issue rather than Jboss.

            -Raj

            • 3. Re: CMT, my rollback doesn't seem to be working
              n2

              we are working with mssqlserver 8.0 + hibernate2 + jboss3.2.1. so it is not a mysql-problem.

              it could be a hibernate problem and not a jboss-problem.