Using iBatis within stateless EJB problem?

harryajh
2004-11-26
2013-04-11
  • harryajh
    harryajh
    2004-11-26

    Running on weblogic 8.1 (sp3) on win 2000 (sp4)

    I have 2 stateless EJB's, say EJB1 & EJB2,  EJB2 is basically a front for ibatis. Typical methods look like -

      public void insertProjectHeader(Project_DTO oProj) throws EJBException, RemoteException
      {
        return projectDao.getProjectAction(oProj);
      }

      public void insertProjectMilestone(ProjectMilestone_DTO oMile, long id)
      {
        return projectDao.insertProjectMilestone(oMile, id);
      }

    I have this method in EJB1 -

      public void insertProject(Project_DTO oProj) throws EJBException, RemoteException
      {
        ejb2.insertProjectHeader(oProj);

        // Insert 3 fixed milestones
        ejb2.insertProjectMilestone(new ProjectMilestone_DTO(), 1));
        ejb2.insertProjectMilestone(new ProjectMilestone_DTO(), 2));
        ejb2.insertProjectMilestone(new ProjectMilestone_DTO(), 3));
      }

    I want this "insertProject" method to be wrapped in it's own transaction & be able to detect if any method fails to roll back!

    I have this in my ejb-jar.xml file -

    ...
    <container-transaction >
       <method >
          <ejb-name>ProjectController</ejb-name>
          <method-intf>Remote</method-intf>
          <method-name>insertProject</method-name>
          <method-params>
             <method-param>xyz.Project_DTO</method-param>
          </method-params>
       </method>
       <trans-attribute>Required</trans-attribute>
    </container-transaction>
    ...

    Which I thought was enough to get this working, however when the statement "oDataEngine.insertProjectHeader(oProj)" is executed I get this exception -

    <Nov 26, 2004 12:19:19 PM GMT> <Warning> <JDBC> <BEA-001074> <A JDBC pool connection leak was detected. A connection leak occurs when a connection obtained from the pool was not closed explicitly by calling close() and then was disposed by the garbage collector and returned to the connection pool. The following stack trace at create shows where the leaked connection was created.  [Null exception passed, creating stack trace for offending caller]
        at weblogic.utils.StackTraceUtils.throwable2StackTrace(StackTraceUtils.java:28)
        at weblogic.jdbc.wrapper.JTSConnection.finalizeInternal(JTSConnection.java:115)
        at weblogic.jdbc.wrapper.JTSConnection_oracle_jdbc_driver_OracleConnection.finalize(Unknown Source)
        at java.lang.ref.Finalizer.invokeFinalizeMethod(Native Method)
        at java.lang.ref.Finalizer.runFinalizer(Finalizer.java:83)
        at java.lang.ref.Finalizer.access$100(Finalizer.java:14)
        at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:160)
    >
    javax.transaction.TransactionRolledbackException: EJB Exception: : com.ibatis.dao.client.DaoException: Error ending SQL Map transaction.  Cause: java.sql.SQLException: Cannot call Connection.rollback in distributed transaction.  Transaction Manager will commit the resource manager when the distributed transaction is committed.
    Caused by: java.sql.SQLException: Cannot call Connection.rollback in distributed transaction.  Transaction Manager will commit the resource manager when the distributed transaction is committed.
        at com.ibatis.dao.engine.transaction.sqlmap.SqlMapDaoTransaction.rollback(SqlMapDaoTransaction.java:42)
        at com.ibatis.dao.engine.transaction.sqlmap.SqlMapDaoTransactionManager.rollbackTransaction(SqlMapDaoTransactionManager.java:66)
        at com.ibatis.dao.engine.impl.DaoContext.endTransaction(DaoContext.java:103)
        at com.ibatis.dao.engine.impl.DaoProxy.invoke(DaoProxy.java:66)
        at $Proxy13.insertProject(Unknown Source)
    ...

    Totally lost - any ideas?

    many thanks

    harry

     
    • harryajh
      harryajh
      2004-11-26

      on my god it works! - found by changing

      <transactionManager type="JDBC">

      to

      <transactionManager type="EXTERNAL">

      Works perfectly - only questions now are -

      is it safe?

      is it correct way to do this?

      yipppeeeeeeeeee!