How do i emulate container managed 'Required'?

Discussions

EJB design: How do i emulate container managed 'Required'?

  1. How do i emulate container managed 'Required'? (5 messages)

    I have a stateless session bean with a bean managed transaction. However, i would like to emulate the container managed approach of 'Required', ie if there is already a transaction in progress then 'join' it, otherwise start a new one.

    How do i do that?

    Threaded Messages (5)

  2. SessionContext sessionContext = null;

    public void setSessionContext(SessionContext sctx) {
     this.sessionContext = sctx;
    }

    public void sampleMethod () {
     UserTransaction ut = sessionContext.getUserTransaction();
     int status = ut.getStatus();
     if(status == Status.STATUS_NO_TRANSACTION) {
      ut.begin();
      ...
      ut.commit();
     } else if (status == Status.STATUS_ACTIVE) {
      ...
     }
    }

    Will this solve the problem
  3. nice try...[ Go to top ]

    Thanks for responding. i got excited when i saw your answer, but in the end it doesn't work (using WAS 5.1).

    It never seems to 'join' the existing xaction (the status is never STATUS_ACTIVE).

    I've been trying various things for a while now and am going to give up and try and get my requirements changed!

    Thanks anyway.
  4. in the ejb-jar.xml set the trans-attribute to required for your method eg if the method is tryThis(). I think this should help.


       <assembly-descriptor>
        <container-transaction>
          <method>
            <ejb-name>TryBean</ejb-name>
            <method-name>tryThis</method-name>
          </method>
          <trans-attribute>Required</trans-attribute>
        </container-transaction>
      </assembly-descriptor>
  5. sorry..[ Go to top ]

    plz ignore the above reply by me...mea culpa...
  6. If you don't use CMT or CMP...[ Go to top ]

    Hi,

    You could try to use the Atomikos Transactions product for this.

    In particular, you can use Transactions to:
    -integrate an external JTA implementation in your J2EE application server
    -deploy XA-capable JDBC DataSources
    -perform transactions over them with BMT
    -in a J2EE server-independent way (it works on any J2EE container)

    However, if you are using Websphere's CMT then this may not mix well. You would have similar problems then. Currently, we only support JBoss CMT.

    If you're interested, feel free to check out http://www.atomikos.com for more information and download.

    HTH,
    Guy Pardon
    The Transaction Processing Company