0 Replies Latest reply on Jul 24, 2002 6:01 PM by Stephen

    Transaction Rollback Exception in Session and BMP Entity Bea

    Stephen Newbie

      I have one BMP Entity Bean (Table3BeanBMP) and one Session Bean (mySessionBean).

      The Entity Bean (Table3BeanBMP) is mapping to a table.

      The Session Bean (mySessionBean) has one function name "method1". The purpose of "method1" is to find a record from Table3BeanBMP. Very simple.

      So, I use JBuilder to generate a EJB test client object to test the session bean.

      Attached are the error I got from the JBoss when I invoked the "method1" from mySessionBean and the ejb-jar.xml content.

      I think this might have something to do with the driver. I am using SUN jdbc-odbc driver. The jboss version is 2.4.6. Database is MSDE (similar to MSSQL 7.0).

      Thanks for any reponses.


      [INFO,STDERR] JBoss-2.4.6 Started in 0m:10s.956
      [INFO,XAPoolDataSource] Creating XA Pool
      [INFO,XAPoolDataSource] Creating XA Pool
      [ERROR,Table3] TRANSACTION ROLLBACK EXCEPTION:
      javax.transaction.TransactionRolledbackException: Error executing SQL SELECT "my
      more" FROM TABLE3 WHERE "myid3" = ? AND "myname3" = ?: java.sql.SQLException: [M
      icrosoft][ODBC SQL Server Driver]Connection is busy with results for another hst
      mt; nested exception is:
      javax.ejb.EJBException: Error executing SQL SELECT "mymore" FROM TABLE3
      WHERE "myid3" = ? AND "myname3" = ?: java.sql.SQLException: [Microsoft][ODBC SQL
      Server Driver]Connection is busy with results for another hstmt
      javax.ejb.EJBException: Error executing SQL SELECT "mymore" FROM TABLE3 WHERE "m
      yid3" = ? AND "myname3" = ?: java.sql.SQLException: [Microsoft][ODBC SQL Server
      Driver]Connection is busy with results for another hstmt
      at tabletest.Table3BeanBMP.ejbLoad(Table3BeanBMP.java:91)
      at java.lang.reflect.Method.invoke(Native Method)
      at org.jboss.ejb.plugins.BMPPersistenceManager.loadEntity(BMPPersistence
      Manager.java:329)
      at org.jboss.ejb.plugins.EntitySynchronizationInterceptor.invoke(EntityS
      ynchronizationInterceptor.java:287)
      at org.jboss.ejb.plugins.EntityInstanceInterceptor.invoke(EntityInstance
      Interceptor.java:197)
      at org.jboss.ejb.plugins.EntityLockInterceptor.invoke(EntityLockIntercep
      tor.java:125)
      at org.jboss.ejb.plugins.TxInterceptorCMT.invokeNext(TxInterceptorCMT.ja
      va:138)
      at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxIntercep
      torCMT.java:347)
      at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:1
      00)
      at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.
      java:127)
      at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:170)
      at org.jboss.ejb.EntityContainer.invoke(EntityContainer.java:436)
      at org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoker.invoke(JRMPCon
      tainerInvoker.java:506)
      at org.jboss.ejb.plugins.jrmp.interfaces.GenericProxy.invokeContainer(Ge
      nericProxy.java:335)
      at org.jboss.ejb.plugins.jrmp.interfaces.EntityProxy.invoke(EntityProxy.
      java:133)
      at $Proxy6.getMymore(Unknown Source)
      at tabletest.mySessionBean.method1(mySessionBean.java:47)
      at java.lang.reflect.Method.invoke(Native Method)
      at org.jboss.ejb.StatefulSessionContainer$ContainerInterceptor.invoke(St
      atefulSessionContainer.java:672)
      at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.
      java:127)
      at org.jboss.ejb.plugins.StatefulSessionInstanceInterceptor.invoke(State
      fulSessionInstanceInterceptor.java:255)
      at org.jboss.ejb.plugins.TxInterceptorCMT.invokeNext(TxInterceptorCMT.ja
      va:138)
      at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxIntercep
      torCMT.java:347)
      at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:1
      00)
      at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:170)
      at org.jboss.ejb.StatefulSessionContainer.invoke(StatefulSessionContaine
      r.java:347)
      at org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoker.invoke(JRMPCon
      tainerInvoker.java:412)
      at java.lang.reflect.Method.invoke(Native Method)
      at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:241)
      at sun.rmi.transport.Transport$1.run(Transport.java:152)
      at java.security.AccessController.doPrivileged(Native Method)
      at sun.rmi.transport.Transport.serviceCall(Transport.java:148)
      at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:4
      65)
      at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport
      .java:706)
      at java.lang.Thread.run(Thread.java:484)
      [INFO,STDERR] Error executing SQL SELECT "mymore" FROM TABLE3 WHERE "myid3" = ?
      AND "myname3" = ?: java.sql.SQLException: [Microsoft][ODBC SQL Server Driver]Con
      nection is busy with results for another hstmt; nested exception is:
      javax.ejb.EJBException: Error executing SQL SELECT "mymore" FROM TABLE3
      WHERE "myid3" = ? AND "myname3" = ?: java.sql.SQLException: [Microsoft][ODBC SQL
      Server Driver]Connection is busy with results for another hstmt



      ejb-jar.xml
      ===========
      <?xml version="1.0" encoding="UTF-8"?>

      <ejb-jar>
      <enterprise-beans>

      <ejb-name>mySession</ejb-name>
      tabletest.mySessionHome
      tabletest.mySession
      <ejb-class>tabletest.mySessionBean</ejb-class>
      <session-type>Stateful</session-type>
      <transaction-type>Container</transaction-type>


      <ejb-name>Table3</ejb-name>
      tabletest.Table3Home
      tabletest.Table3
      <ejb-class>tabletest.Table3BeanBMP</ejb-class>
      <persistence-type>Bean</persistence-type>
      <prim-key-class>tabletest.Table3PK</prim-key-class>
      False
      <resource-ref>
      <res-ref-name>jdbc/ppppDS</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
      </resource-ref>


      <ejb-name>tabletest</ejb-name>
      tabletest.tabletestHome
      tabletest.tabletestRemote
      <ejb-class>tabletest.tabletest</ejb-class>
      <persistence-type>Bean</persistence-type>
      <prim-key-class>java.lang.String</prim-key-class>
      False

      </enterprise-beans>
      <assembly-descriptor>
      <container-transaction>

      <ejb-name>Table3</ejb-name>
      <method-name>*</method-name>


      <ejb-name>tabletest</ejb-name>
      <method-name>*</method-name>


      <ejb-name>mySession</ejb-name>
      <method-name>*</method-name>

      <trans-attribute>Required</trans-attribute>
      </container-transaction>
      </assembly-descriptor>
      </ejb-jar>


      Table3BeanBMP.java
      ==================
      public class Table3BeanBMP extends Table3Bean {
      DataSource dataSource;

      :
      :
      :
      public void ejbLoad() {
      Table3PK key = (Table3PK) entityContext.getPrimaryKey();
      myid3 = key.myid3;
      myname3 = key.myname3;
      Connection connection = null;
      PreparedStatement statement = null;
      try {
      connection = dataSource.getConnection();
      statement = connection.prepareStatement("SELECT \"mymore\" FROM TABLE3 WHERE \"myid3\" = ? AND \"myname3\" = ?");
      statement.setInt(1, myid3);
      statement.setString(2, myname3);
      ResultSet resultSet = statement.executeQuery();
      if (!resultSet.next()) {
      throw new NoSuchEntityException("Row does not exist");
      }
      this.mymore = resultSet.getString(1);
      }
      catch(SQLException e) {
      throw new EJBException("Error executing SQL SELECT \"mymore\" FROM TABLE3 WHERE \"myid3\" = ? AND \"myname3\" = ?: " + e.toString());
      }
      finally {
      closeConnection(connection, statement);
      }
      super.ejbLoad();
      }
      public void ejbStore() {
      super.ejbStore();
      Connection connection = null;
      PreparedStatement statement = null;
      try {
      connection = dataSource.getConnection();
      statement = connection.prepareStatement("UPDATE TABLE3 SET \"mymore\" = ? WHERE \"myid3\" = ? AND \"myname3\" = ?");
      statement.setString(1, mymore);
      statement.setInt(2, myid3);
      statement.setString(3, myname3);
      if (statement.executeUpdate() < 1) {
      throw new NoSuchEntityException("Row does not exist");
      }
      }
      catch(SQLException e) {
      throw new EJBException("Error executing SQL UPDATE TABLE3 SET \"mymore\" = ? WHERE \"myid3\" = ? AND \"myname3\" = ?: " + e.toString());
      }
      finally {
      closeConnection(connection, statement);
      }
      }
      public Table3PK ejbFindByPrimaryKey(Table3PK table3Key) throws ObjectNotFoundException {
      Connection connection = null;
      PreparedStatement statement = null;
      try {
      connection = dataSource.getConnection();
      statement = connection.prepareStatement("SELECT \"myid3\", \"myname3\" FROM TABLE3 WHERE \"myid3\" = ? AND \"myname3\" = ?");
      statement.setInt(1, table3Key.myid3);
      statement.setString(2, table3Key.myname3);
      ResultSet resultSet = statement.executeQuery();
      if (!resultSet.next()) {
      throw new ObjectNotFoundException("Primary key does not exist");
      }
      return table3Key;
      }
      catch(SQLException e) {
      throw new EJBException("Error executing SQL SELECT \"myid3\", \"myname3\" FROM TABLE3 WHERE \"myid3\" = ? AND \"myname3\" = ?: " + e.toString());
      }
      finally {
      closeConnection(connection, statement);
      }
      }
      void closeConnection(Connection connection, Statement statement) {
      try {
      if (statement != null) {
      statement.close();
      }
      }
      catch(SQLException e) {
      }
      try {
      if (connection != null) {
      connection.close();
      }
      }
      catch(SQLException e) {
      }
      }
      public void setEntityContext(EntityContext entityContext) {
      super.setEntityContext(entityContext);
      try {
      javax.naming.Context context = new javax.naming.InitialContext();
      try {
      dataSource = (DataSource) context.lookup("java:comp/env/jdbc/ppppDS");
      }
      catch(Exception e) {
      throw new EJBException("Error looking up dataSource: " + e.toString());
      }
      }
      catch(Exception e) {
      throw new EJBException("Error initializing context:" + e.toString());
      }
      }
      public void unsetEntityContext() {
      super.unsetEntityContext();
      this.entityContext = null;
      }
      }