0 Replies Latest reply on Oct 1, 2001 3:13 PM by chsiao

    Cannot commit a record through a staeless session bean

    chsiao

      I follow JBoss documentation and setup JBoss 2.4.1 and SQLServerPool (see below). In ejb-jar.xml, I set the value of trans-attribute to "Required". When I run the java code (see below), it seems that the record is inserted successfully. However, when I open the table and the record is not there. Thus, I think the transaction is not committed when the connection is closed (see the JBoss log below). What do I need to do to set the database tranaction right? Please help. Thanks.

      SQLServerPool setup:

      org.jboss.pool.jdbc.xa.wrapper.XADataSourceImpl
      SQLServerPool
      jdbc:odbc:odbcname
      username
      password
      true
      TRANSACTION_SERIALIZABLE


      Java Code:

       public boolean insertData()
       {
       boolean isInserted = true;
       Connection conn = null;
       Statement stmt = null;
       try {
       InitialContext context = new InitialContext();
       DataSource ds = (DataSource) context.lookup("java:/SQLServerPool");
       conn = ds.getConnection();
       stmt = conn.createStatement();
       String sqlString = "insert into staff(firstname, lastname) values ('Jason', 'Smith')";
       int status = stmt.executeUpdate(sqlString);
       System.out.println(status);
       } catch (NamingException ex) {
       System.out.println("NamingException caught when trying to get data source from JNDI");
       ex.printStackTrace();
       isInserted = false;
       } catch (SQLException ex) {
       ex.printStackTrace();
       isInserted = false;
       } catch (Exception ex) {
       ex.printStackTrace();
       isInserted = false;
       } finally {
       try {
       if (stmt!=null) stmt.close();
       if (conn!=null) conn.close();
       } catch (Exception ex) {
       ex.printStackTrace();
       }
       }
       return isInserted;
       }
      

      JBoss Log:
      [SQLServerPool] No transaction right now.
      [SQLServerPool] Pool SQLServerPool [1/1/Unlimited] gave out pooled object: org.j
      boss.pool.jdbc.xa.wrapper.XAConnectionImpl@1b42e6
      [Default] 1
      [Default]
      [SQLServerPool] Pool SQLServerPool [0/1/Unlimited] returned object org.jboss.poo
      l.jdbc.xa.wrapper.XAConnectionImpl@1b42e6 to the pool.