0 Replies Latest reply on May 22, 2002 9:16 AM by Joerg Brueck

    transaction doesn't work

    Joerg Brueck Newbie

      Hi,

      example application:

      public class TestBean implements SessionBean {

      private SessionContext c_sctSContext = null;

      // remember the Connection
      private Connection dbConnection;

      public void ejbCreate() {
      try {
      this.dbConnection = initConnection();
      } catch(Exception e) {
      }
      }

      public void ejbPassivate() {
      try {
      this.dbConnection.close();
      this.dbConnection = null;
      } catch(Exception e) {
      }
      }

      public void ejbRemove() {
      try {
      this.dbConnection.close();
      this.dbConnection = null;
      } catch(Exception e) {
      }
      }

      public void ejbActivate() {
      try {
      this.dbConnection = initConnection();
      } catch(Exception e) {
      }
      }

      public Connection initConnection() throws Exception {
      Context initCtx = new InitialContext();
      DataSource ds = (DataSource)initCtx.lookup( getDataSourceName() );
      this.dbConnection = ds.getConnection();
      return this.dbConnection;
      }

      public void doSomething1() throws RemoteException{
      UserTransaction ut = c_sctSContext.getUserTransaction();
      ut.begin();
      try {
      stmt = this.dbConnection.createStatement();
      stmt.executeUpdate(…);
      stmt.executeUpdate(…);
      ut.commit();
      } catch(Exception e) {
      ut.rollback();
      }
      }

      public void doSomething2() throws RemoteException{
      ...
      }

      }
      test environment: JBoss 2.4.4
      Database: Oracle 8i

      TestBean is a stateful session bean. Because I don’t want to initiate the connection for every function I use a class variable dbConnection. After passivation of the bean I set the connection again, because the connection is not serializable.
      I don’t get any error message or exception while executing ut.commit in function doSomething1, but the record is not visible in the database.
      It seems that the transaction is not committed. Is this a jboss specific behaviour?
      If the function this.dbConnection = initConnection() is executed before stmt = this.dbConnection.createStatement() in function doSomething1 the transaction works fine.

      thanks in advance,
      Joerg