2 Replies Latest reply on May 16, 2006 4:29 AM by andreas_austing

    EJB3 and oTM

    andreas_austing Newbie

      Hello,
      i configured jboss to use another TM, bound to java:/TransactionManager. ejb2 session beans are using this TM, but ejb3 session beans not (JBoss 4.0.3SP1/EJB3.0-RC5).

      - how can i configure JBoss+EJB3 to use the TM?
      - is it possible to inject the TM and/or UserTransaction? Deployment Exception below:

       java.lang.IllegalStateException: Container TravelAgencyBean: it is illegal to inject UserTransaction into a CMT bean
      

      The deployment descriptor:
      <session>
       <ejb-name>TravelAgency</ejb-name>
       <remote>de.ol.uni.inf.jass.example.ejb3.TravelAgencyRemote</remote>
       <local>de.ol.uni.inf.jass.example.ejb3.TravelAgencyLocal</local>
       <ejb-class>de.ol.uni.inf.jass.example.ejb3.TravelAgencyBean</ejb-class>
       <session-type>Stateless</session-type>
       <transaction-type>Bean</transaction-type>
       <resource-ref>
       <res-ref-name>UserTransaction</res-ref-name>
       <res-type>javax.transaction.UserTransaction</res-type>
       <res-auth>Container</res-auth>
       <res-sharing-scope>Shareable</res-sharing-scope>
       <mapped-name>ut</mapped-name>
       <injection-target>
       <injection-target-class>de.ol.uni.inf.jass.example.ejb3.TravelAgencyBean</injection-target-class>
       <injection-target-name>ut</injection-target-name>
       </injection-target>
       </resource-ref>
       </session>
      

      Thanks,
      Andreas.

        • 1. Re: EJB3 and oTM
          andreas_austing Newbie

          Question 2:
          I upgraded to jboss-4.0.4CR2 and EJB-3.0-RC6.
          I found: http://jboss.org/index.html?module=bb&op=viewtopic&t=72031
          Deployment no works, config:

          <session>
           <ejb-name>TravelAgency</ejb-name>
           <remote>de.ol.uni.inf.jass.example.ejb3.TravelAgencyRemote</remote>
           <local>de.ol.uni.inf.jass.example.ejb3.TravelAgencyLocal</local>
           <ejb-class>de.ol.uni.inf.jass.example.ejb3.TravelAgencyBean</ejb-class>
           <session-type>Stateless</session-type>
           <transaction-type>Bean</transaction-type>
           <resource-ref>
           <res-ref-name>transactionManager</res-ref-name>
           <res-type>javax.transaction.TransactionManager</res-type>
           <res-auth>Container</res-auth>
           <mapped-name>java:/TransactionManager</mapped-name>
           <injection-target>
           <injection-target-class>de.ol.uni.inf.jass.example.ejb3.TravelAgencyBean</injection-target-class>
           <injection-target-name>transactionManager</injection-target-name>
           </injection-target>
           </resource-ref>
           </session>
          

          But the TM is not set:
          public void makeReservation(String name, int seats, int rooms)
           throws NotEnoughSeatsException, NotEnoughRoomsException {
           if(transactionManager == null) {
           throw new RuntimeException("TM not set!");
           }
           try {
           transactionManager.begin();
           log.info("called makeReservation(name=" + name + ", seats=" + seats
           + ", rooms=" + rooms + ");");
           transactionManager.commit();
           } catch (Exception e) {
           e.printStackTrace();
           }
           }
          


          • 2. Re: EJB3 and oTM
            andreas_austing Newbie

            I debugged a little bit more. It seams, that the EJB3 container recieves a TM-Singelton by calling TxManager.getInstance() instead of doing a JNDI-lookup to java:/TransactionManager. My bean and the logs:

            Bean:

            package de.ol.uni.inf.jass.example.ejb3;
            
            import [...]
            
            @Stateless
            @Local(TravelAgencyLocal.class)
            @Remote(TravelAgencyRemote.class)
            public class TravelAgencyBean implements TravelAgencyLocal, TravelAgencyRemote {
            
             private static Logger log = Logger.getLogger(TravelAgencyBean.class
             .getName());
            
             private TransactionManager tm;
             private DataSource airlineDatabase;
            
             public void makeReservation(String name, int seats, int rooms)
             throws NotEnoughSeatsException, NotEnoughRoomsException {
             log.info("called makeReservation(name=" + name + ", seats=" + seats
             + ", rooms=" + rooms + ");");
            
             checkTransactionManager();
             checkAirlineDatabase();
            
             Connection airlineConnection = null;
             Statement freeSeatsStatement = null;
             ResultSet freeSeatsResultSet = null;
             try {
             tm.begin();
            
             airlineConnection = airlineDatabase.getConnection();
             freeSeatsStatement = airlineConnection.createStatement();
             freeSeatsResultSet = freeSeatsStatement
             .executeQuery("SELECT seats FROM flights");
             freeSeatsResultSet.next();
             int freeSeats = freeSeatsResultSet.getInt(1);
             if ((freeSeats - seats) < 0) {
             tm.rollback();
             throw new NotEnoughSeatsException("Not enough seats, free: "
             + freeSeats);
             }
            
             tm.commit();
             } catch (NotEnoughSeatsException e) {
             throw e;
             } catch (Exception e) {
             throw new EJBException(e);
             } finally {
             try {
             freeSeatsResultSet.close();
             freeSeatsStatement.close();
             airlineConnection.close();
             } catch (Exception e) {
             log.severe(e.getMessage());
             }
             }
             }
            
             public TransactionManager getTransactionManager() {
             return tm;
             }
             public void setTransactionManager(TransactionManager transactionManager) {
             this.tm = transactionManager;
             }
             private void checkTransactionManager() {
             if (tm == null) {
             log.warning("transactionManager is null.");
             try {
             Context ctx = new InitialContext();
             Object tm = ctx.lookup("java:/TransactionManager");
             tm = (TransactionManager) tm;
             } catch (Exception e) {
             throw new RuntimeException("could not init the TM.");
             }
             }
             }
            
             public DataSource getAirlineDatabase() {
             return airlineDatabase;
             }
             public void setAirlineDatabase(DataSource airlineDatabase) {
             this.airlineDatabase = airlineDatabase;
             }
             private void checkAirlineDatabase() {
             if (airlineDatabase == null) {
             log.warning("airlineDatabase is null.");
             try {
             Context ctx = new InitialContext();
             Object db = ctx.lookup("java:/TAAirlineDS");
             airlineDatabase = (DataSource) db;
             } catch (NamingException e) {
             e.printStackTrace();
             }
             }
             }
            }
            


            The Log for makeReservation()
            2006-05-16 10:09:25,172 TRACE [org.jboss.tm.TransactionImpl] Created new instance or tx=TransactionImpl:XidImpl[FormatId=257, GlobalId=bonus.chaoswg.lan/7, BranchQual=, localId=7]
            2006-05-16 10:09:25,172 TRACE [org.jboss.tm.TxManager] began tx: TransactionImpl:XidImpl[FormatId=257, GlobalId=bonus.chaoswg.lan/7, BranchQual=, localId=7]
            2006-05-16 10:09:25,173 ERROR [STDERR] 16.05.2006 10:09:25 de.ol.uni.inf.jass.example.ejb3.TravelAgencyBean makeReservation
            INFO: called makeReservation(name=austing, seats=3, rooms=2);
            2006-05-16 10:09:25,173 ERROR [STDERR] 16.05.2006 10:09:25 de.ol.uni.inf.jass.example.ejb3.TravelAgencyBean checkTransactionManager
            WARNUNG: transactionManager is null.
            2006-05-16 10:09:25,174 DEBUG [de.ol.uni.inf.jass.hls.tpc.jboss.TransactionManagerService] Returning the JASS-TM Singelton. TransactionManagerService.getObjectInstance()
            2006-05-16 10:09:25,175 ERROR [STDERR] 16.05.2006 10:09:25 de.ol.uni.inf.jass.example.ejb3.TravelAgencyBean checkAirlineDatabase
            WARNUNG: airlineDatabase is null.
            2006-05-16 10:09:25,178 DEBUG [org.objectweb.jass.as.ActivityService] Starting a ROOT activity
            2006-05-16 10:09:25,178 DEBUG [org.objectweb.jass.as.ActivityIdGenerator] New Activity Id Created: http://bonus.chaoswg.lan:1147763021090/18
            2006-05-16 10:09:25,178 DEBUG [org.objectweb.jass.as.ActivityImpl] STARTING ACTIVITY http://bonus.chaoswg.lan:1147763021090/18
            2006-05-16 10:09:25,178 DEBUG [org.objectweb.jass.as.ActivityImpl] Timeout = 300
            2006-05-16 10:09:25,178 DEBUG [org.objectweb.jass.as.ActivityImpl] http://bonus.chaoswg.lan:1147763021090/18 STARTED!!!
            2006-05-16 10:09:25,179 DEBUG [de.ol.uni.inf.jass.hls.tpc.XidFactory] Created new Xid: XidImpl[FormatId=257, GlobalId=bonus.chaoswg.lan:1147763021090/18, BranchQual=, localId=18]
            2006-05-16 10:09:25,179 DEBUG [de.ol.uni.inf.jass.hls.tpc.TransactionServiceManager] Transaction associated with current thread.
            2006-05-16 10:09:25,179 DEBUG [de.ol.uni.inf.jass.hls.tpc.TransactionUtils] Status: activityStatus=javax.activity.Status.StatusActive, completionStatus=javax.activity.CompletionStatus.CompletionStatusFail, transactionStatus=javax.transaction.Status.STATUS_ACTIVE
            2006-05-16 10:09:25,519 TRACE [org.jboss.resource.connectionmanager.JBossManagedConnectionPool] supplying new ManagedConnection: org.jboss.resource.connectionmanager.TxConnectionManager$TxConnectionEventListener@1d9d7ab[state=NORMAL mc=org.jboss.resource.adapter.jdbc.local.LocalManagedConnection@de4588 handles=0 lastUse=1147766965519 permit=false trackByTx=false mcp=org.jboss.resource.connectionmanager.JBossManagedConnectionPool$OnePool@22e349 context=org.jboss.resource.connectionmanager.InternalManagedConnectionPool@780515 xaResource=org.jboss.resource.connectionmanager.TxConnectionManager$LocalXAResource@a6fed5 txSync=null]
            2006-05-16 10:09:25,519 TRACE [org.jboss.resource.connectionmanager.JBossManagedConnectionPool] Got connection from pool tracked by transaction org.jboss.resource.connectionmanager.TxConnectionManager$TxConnectionEventListener@1d9d7ab[state=NORMAL mc=org.jboss.resource.adapter.jdbc.local.LocalManagedConnection@de4588 handles=0 lastUse=1147766965519 permit=true trackByTx=false mcp=org.jboss.resource.connectionmanager.JBossManagedConnectionPool$OnePool@22e349 context=org.jboss.resource.connectionmanager.InternalManagedConnectionPool@780515 xaResource=org.jboss.resource.connectionmanager.TxConnectionManager$LocalXAResource@a6fed5 txSync=null] tx=de.ol.uni.inf.jass.hls.tpc.TransactionImpl@1a489ad [InUse/Available/Max]: [4/16/20]
            2006-05-16 10:09:25,519 TRACE [org.jboss.resource.connectionmanager.JBossManagedConnectionPool] Using connection from pool tracked by transaction org.jboss.resource.connectionmanager.TxConnectionManager$TxConnectionEventListener@1d9d7ab[state=NORMAL mc=org.jboss.resource.adapter.jdbc.local.LocalManagedConnection@de4588 handles=0 lastUse=1147766965519 permit=true trackByTx=true mcp=org.jboss.resource.connectionmanager.JBossManagedConnectionPool$OnePool@22e349 context=org.jboss.resource.connectionmanager.InternalManagedConnectionPool@780515 xaResource=org.jboss.resource.connectionmanager.TxConnectionManager$LocalXAResource@a6fed5 txSync=null] tx=de.ol.uni.inf.jass.hls.tpc.TransactionImpl@1a489ad [InUse/Available/Max]: [4/16/20]
            2006-05-16 10:09:25,520 DEBUG [de.ol.uni.inf.jass.hls.tpc.TransactionUtils] Status: activityStatus=javax.activity.Status.StatusActive, completionStatus=javax.activity.CompletionStatus.CompletionStatusFail, transactionStatus=javax.transaction.Status.STATUS_ACTIVE
            2006-05-16 10:09:25,520 DEBUG [de.ol.uni.inf.jass.hls.tpc.XidFactory] Created new Xid (branch): XidImpl[FormatId=257, GlobalId=bonus.chaoswg.lan:1147763021090/18, BranchQual=, localId=18]
            2006-05-16 10:09:25,520 DEBUG [org.objectweb.jass.as.ActivityImpl] http://bonus.chaoswg.lan:1147763021090/18
            2006-05-16 10:09:25,520 DEBUG [org.objectweb.jass.as.ActivityImpl] SignalSet de.ol.uni.inf.jass.hls.tpc.TwoPhaseCommitSignalSet not yet registered.
            2006-05-16 10:09:25,520 DEBUG [org.objectweb.jass.as.ActivityImpl] Registering SignalSet and adding action...
            2006-05-16 10:09:25,520 DEBUG [org.objectweb.jass.as.ActivityImpl] SignalSet de.ol.uni.inf.jass.hls.tpc.TwoPhaseCommitSignalSet registered
            2006-05-16 10:09:25,520 DEBUG [org.objectweb.jass.as.ActivityImpl] Action added!!!
            2006-05-16 10:09:25,520 DEBUG [org.objectweb.jass.as.ActivityImpl] Actions registered = 1
            2006-05-16 10:09:25,520 DEBUG [de.ol.uni.inf.jass.hls.tpc.XAResourceAction] startResource(XidImpl[FormatId=257, GlobalId=bonus.chaoswg.lan:1147763021090/18, BranchQual=, localId=18]) entered: org.jboss.resource.connectionmanager.TxConnectionManager$LocalXAResource@a6fed5 flags=0
            2006-05-16 10:09:25,692 DEBUG [org.objectweb.jass.as.ActivityService] completeWithStatus SocketServerInvokerThread-127.0.0.1-6
            2006-05-16 10:09:25,693 DEBUG [org.objectweb.jass.as.ActivityImpl] COMPLETING ACTIVITY http://bonus.chaoswg.lan:1147763021090/18
            2006-05-16 10:09:25,693 DEBUG [org.objectweb.jass.as.ActivityImpl] WITH COMPLETION_STATUS_FAIL
            2006-05-16 10:09:25,693 DEBUG [org.objectweb.jass.as.ActivityImpl] SignalSet de.ol.uni.inf.jass.hls.tpc.TwoPhaseCommitSignalSet already registered
            2006-05-16 10:09:25,693 DEBUG [org.objectweb.jass.as.ActivityImpl] Processing Completion SignalSet -> de.ol.uni.inf.jass.hls.tpc.TwoPhaseCommitSignalSet2006-05-16 10:09:25,693 DEBUG [de.ol.uni.inf.jass.hls.tpc.TransactionUtils] Status: activityStatus=javax.activity.Status.StatusCompleting, completionStatus=javax.activity.CompletionStatus.CompletionStatusFail, transactionStatus=javax.transaction.Status.STATUS_ROLLING_BACK
            2006-05-16 10:09:25,693 DEBUG [de.ol.uni.inf.jass.hls.tpc.TwoPhaseCommitSignalSet] Number of XAResources: 1
            2006-05-16 10:09:25,693 DEBUG [org.objectweb.jass.as.ActivityImpl] Sending de.ol.uni.inf.jass.hls.tpc.RollbackSignal signal...
            2006-05-16 10:09:25,693 DEBUG [org.objectweb.jass.as.ActivityImpl] # of registered actions = 1
            2006-05-16 10:09:25,693 DEBUG [org.objectweb.jass.as.ActivityImpl] Sending number: 0
            2006-05-16 10:09:25,693 DEBUG [de.ol.uni.inf.jass.hls.tpc.XAResourceAction] Got Signal: de.ol.uni.inf.jass.hls.tpc.RollbackSignal Instance: de.ol.uni.inf.jass.hls.tpc.XAResourceAction@40d1b0
            2006-05-16 10:09:25,746 DEBUG [de.ol.uni.inf.jass.hls.tpc.TwoPhaseCommitSignalSet] Got Outcome: de.ol.uni.inf.jass.hls.tpc.protocol.SuccessOutcome
            2006-05-16 10:09:25,746 DEBUG [de.ol.uni.inf.jass.hls.tpc.TwoPhaseCommitSignalSet] ABORT
            2006-05-16 10:09:25,746 DEBUG [org.objectweb.jass.as.ActivityImpl] Completion SignalSet processing completed
            2006-05-16 10:09:25,746 DEBUG [org.objectweb.jass.as.ActivityImpl] Final CompletionStatus = COMPLETION_STATUS_FAIL
            2006-05-16 10:09:25,746 DEBUG [org.objectweb.jass.as.ActivityImpl] http://bonus.chaoswg.lan:1147763021090/18 COMPLETED!!!
            2006-05-16 10:09:25,746 DEBUG [org.objectweb.jass.as.ActivityService] Activities in this instance 0
            2006-05-16 10:09:25,746 DEBUG [de.ol.uni.inf.jass.hls.tpc.TransactionServiceManager] Transaction de.ol.uni.inf.jass.hls.tpc.TransactionImpl@1a489ad rolled back.
            2006-05-16 10:09:25,747 TRACE [org.jboss.tm.TransactionImpl] Committing, tx=TransactionImpl:XidImpl[FormatId=257, GlobalId=bonus.chaoswg.lan/7, BranchQual=, localId=7], status=STATUS_ACTIVE
            2006-05-16 10:09:25,747 TRACE [org.jboss.tm.TransactionImpl] Before completion done, tx=TransactionImpl:XidImpl[FormatId=257, GlobalId=bonus.chaoswg.lan/7, BranchQual=, localId=7], status=STATUS_ACTIVE
            2006-05-16 10:09:25,747 TRACE [org.jboss.tm.TransactionImpl] Zero phase commit TransactionImpl:XidImpl[FormatId=257, GlobalId=bonus.chaoswg.lan/7, BranchQual=, localId=7]: No resources.
            2006-05-16 10:09:25,747 TRACE [org.jboss.tm.TransactionImpl] Committed OK, tx=TransactionImpl:XidImpl[FormatId=257, GlobalId=bonus.chaoswg.lan/7, BranchQual=, localId=7]
            2006-05-16 10:09:25,747 TRACE [org.jboss.tm.TxManager] tx timeout is now: 300s
            


            Two Transactions are executed by each TM (org.jboss.tm.TxManager / de.ol.uni.inf.jass.hls.tpc.TransactionManager). The XAResource is only enlisted in the de.ol.uni.inf.jass.hls.tpc.TransactionManager. This TM rolls back because of not enough seats. The org.jboss.tm.TxManager commits with zero phase (No XAResource enlisted).
            So back to my questions:
            - How do i configure EJB3 to only use the de.ol.uni.inf.jass.hls.tpc.TransactionManager?
            - And why does my Injection not work (see check*-Methods)

            Thanks
            Andreas.