Discussions

EJB programming & troubleshooting: transaction roll back problem

  1. transaction roll back problem (2 messages)

    I have a stateful session bean ( bean managed transaction type and method has transaction attribute of not supported) which has a set of supporting classes to it. within one of the supporting classes i want to start a transaction which will insert in three databases or in none. my ejb server is weblogic. i used UserTransaction object to create the transaction. but the problem is the transaction gets created only in ejb server . hence when i give a rollback the transaction is rollbacked in ejb server only . the database changes are already committed . a transcript of the code follows. any idea how to get around this.
    ( demoPool is a connection pool created in weblogic)

    ( Let me know if its possible to use usertransaction object in this manner and if its possible to commit or rollback to all or none of teh three different databases on three different servers)

      try {
                     ctx = new InitialContext();
                     DataSource ds = (DataSource)ctx.lookup("java:/comp/env/jdbc/demoPool");
                    connect = ds.getConnection();
                }
               catch (Exception e)
              {
                e.printStackTrace();
                new EJBException(e);
              }
            InitialContext newcon = new InitialContext();
            UserTransaction utx = (UserTransaction)newcon.lookup("java:comp/UserTransaction");
            try {
                     utx.begin();
                     utx.setTransactionTimeout(0);
                     ps123 = connect.prepareStatement("insert into rep values (2221)");
                     ps123.executeUpdate();
                     if javax.transaction.Status.STATUS_ROLLEDBACK != utx.getStatus())
                          utx.commit();
                    else
                        throw new RollbackException();
              } // try
             catch (RollbackException re)
                    {
                      try {
                               utx.rollback();
                          } catch (Exception syex) {
                                        throw new EJBException ("Rollback failed::::::: " + syex.getMessage());
                                         }
                     re.printStackTrace();
                      throw new EJBException ("Transaction failed: " + re.getMessage());
                    }

    Threaded Messages (2)

  2. transaction roll back problem[ Go to top ]

    first get user transaction object and then get the connection.
  3. transaction roll back problem[ Go to top ]

    hey,
      The weblogic container participates in the transaction only if you use the JTS driver to take the connection from pool. Else you can use the transaction aware data source. refer to the weblogic documentation regarding the data sources.