David Bullock asked me to forward his response to the list.

David:

In response to your question if this discussion is mainly academic ... yes,
it is for me (i.e., I don't currently have a non-XA data source). The
original poster (Satya Komatineni), however, has a non-XA data source. The
original question was if CMTD can be used in the case of a non-XA data
source.

Laurel

-----Original Message-----
From: David Bullock [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, May 16, 2001 10:30 AM
To: Laurel Neustadter
Cc: [EMAIL PROTECTED]
Subject: RE: Is it mandatory to have XADataSource for EJB transactional
su port


Right, I was a little confused.  Specifically, I was thinking of the call to
set the transaction isolation level, that is OK.

commit() and rollback() are still off-limits ( as is setAutoCommit() ... but
it is pretty obvious you *WON'T* be wanting to set this, ever, in an  EJB
application. )

The main reason for this is that you will be wanting the Transaction Manager
of the EJB Server to coordinate 2-phase commits if you make updates to two
or more different resources.

So instead of you doing:


  con1.begin();
  con2.begin();

  // perform processing

  if ( con1workOK && con2workOK && con3workOK ) {

        con1.commit();

        try {

                con2.commit();

        } catch (Exception e) {

                // attempt to undo commit #1
                // ... which will be very difficult,
                // if not impossible

        }
  }



You simply do:


   utrans.begin();


        con1.doWork();
        con2.doWork();

   utrans.commit();


 ... and the server takes care of ensuring the 'all or nothing quality'


If you're not going to be modifying multiple resources, then it should be
fine to not use the UserTransaction, and simply use the transaction-methods
on java.sql.Connection ...

...provided you had the appropriate TX descriptor for your method.  If you
used 'TX_REQUIRES' ( for instance ), and your method got called from another
EJB SessionBean ( for instance ), and there is already a transaction active,
then your changes won't be rolled-back if the caller's transaction fails,
nor can the caller's be called back if your changes fail ( since you are
declining to call setRollback() only on the UserTransaction ).

So the moral of the story is, using UserTransaction is a good idea.  I
suppose this discussion was mainly academic?  Or do you have a JDBC driver
that does not support XA?


cheers,
David


( PS. Laurel, can you forward this to the list ... I'm not at the right
email account to post ).




On Wed, 16 May 2001, Laurel Neustadter wrote:

> Yes, bean-managed/container-managed transaction demarcation is different
> from BMP/CMP.
>
> In Section 11.3.3 of the 1.1 specification, the spec says the
> UserTransaction interface should be used to demarcate transactions ("The
> Bean Provider uses the UserTransaction interface to demarcate
> transactions."), and that commmit() or rollback() should not be called on
> the Connection interface ***within*** a transaction. Are you interpretting
> this to mean that the Connection interface can be used to demarcate
> transactions, as long as you are not also using the UserTransaction
> interface?
>
> Laurel
>
> -----Original Message-----
> From: David Bullock [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, May 16, 2001 9:31 AM
> To: Laurel Neustadter
> Cc: [EMAIL PROTECTED]
> Subject: Re: Is it mandatory to have XADataSource for EJB transactional
> suport
>
>
> Yes, quickly:
>
> 1. EJB supports both 'bean managed' and 'container managed' transactions.
(
> note: this is not the same thing as 'BMP/CMP *persistence*' ).
> 2. To support 'bean managed', is *is* legal to make calls on the
> java.jdbc.Connection, if the deployment descriptor declares that your EJB
is
> bean-managed.
> 3. To support 'container managed' it is *illegal* to make calls on the
> java.jdbc.Connection, if the deployment descriptor delcares that your EJB
is
> container-managed.
>
> Things to note:
>
> a.  when you do 'bean managed persistence', you can only manage the
> transaction from a session bean - this is the appropriate way to begin a
> transaction that spans multiple entity beans
> b.  when your entity beans ask for a JDBC Connection as per your
> java:comp/env/myDriverJNDILocation, the container will give you back the
> same physical connection that you initialised from your SessionBean.
>
> Note also that, in keeping with the idea of a transaction, most containers
> will disallow you to do 'transaction sensitive' operations when CMT is
being
> used ... it is the container's job to specify the transaction isolation
and
> do the commits.  As well, when using BMT, you will want to basically start
> the transaction and commit/rollback at the start and end of the work you
> have to do.
>
>
> Hope that clears it up.
>
> cheers,
> David.
>
>
> On Wed, 16 May 2001, Laurel Neustadter wrote:
>
> > Can anyone explain the underlying technical reasons why EJB does not
> permit
> > transactions to be demarcated via java.sql.Connection? I know the
"what",
> > but don't have a full understanding of the "why".
> >
> > Laurel
> >
> > -----Original Message-----
> > From: Krishnan Subramanian [mailto:[EMAIL PROTECTED]]
> > Sent: Wednesday, May 16, 2001 4:27 AM
> > To: [EMAIL PROTECTED]
> > Subject: Re: Is it mandatory to have XADataSource for EJB transactional
> > suport
> >
> >
> > Laurel,
> >
> > You are absolutely right - I was ranting about the XA & distributed
> > transactions and meant to discuss the java.sql.Connection class and the
> > UserTrasaction in the same breath, but somewhere along I kinda forgot
the
> > UserTransaction.
> >
> > The EJB 1.1 spec does state that a BMP enterprise bean cannot call the
> > Connection.commit or rollback while in the _midst_ of a transaction. or
> for
> > that matter even a setAutoCommit.
> >
> > -krish
> >
> > On Tue, 15 May 2001 18:24:06 -0500, Laurel Neustadter
> > <[EMAIL PROTECTED]> wrote:
> >
> > >According to section 11.3.3 of the EJB 1.1 Specification, a bean may
NOT
> > >control the transaction via the Connection (e.g., may not invoke
commit()
> > or
> > >rollback() on the java.sql.Connection interface). For bean-managed
> > >transaction demarcation, you must use the UserTransaction interface.
> > >
> > >I may be mis-interpreting the post below, but it seems to imply that
you
> > can
> > >use the Connection interface to control and demarcate transactions in
an
> > >EJB.
> > >
> > >I don't know the implications of doing commit/rollback on the
Connection
> > >itself in the case of one data source only.
> > >
> > >Laurel
> > >
> >
> >
>
===========================================================================
> > To unsubscribe, send email to [EMAIL PROTECTED] and include in the
> body
> > of the message "signoff EJB-INTEREST".  For general help, send email to
> > [EMAIL PROTECTED] and include in the body of the message "help".
> >
> >
>
===========================================================================
> > To unsubscribe, send email to [EMAIL PROTECTED] and include in the
> body
> > of the message "signoff EJB-INTEREST".  For general help, send email to
> > [EMAIL PROTECTED] and include in the body of the message "help".
> >
> >
>
>
>
> David Bullock
> LISAsoft Project Lead
> Sun Certified Programmer for the Java 2 Platform
>
>  email: [EMAIL PROTECTED]
> mobile: +61 4 0290 1228
>
> "The key ingredients of success are a crystal-clear goal,
> a realistic attack plan to achieve that goal,
> and consistent, daily action to reach that goal."
>
> Steve Maguire, "Debugging the Development Process".
>
> LISAsoft
> http://www.lisasoft.com/
>
> Adelaide                  Sydney
> --------------------      ------------------------
> 38 Greenhill Rd           Level 3, 228 Pitt Street
> Wayville S.A. 5034        Sydney NSW 2000
> Australia                 Australia
>
> PH  +61 8 8272 1555       PH  +61 2 9283 0877
> FAX +61 8 8271 1199       FAX +61 2 9283 0866
> --------------------      ------------------------
>



David Bullock
LISAsoft Project Lead
Sun Certified Programmer for the Java 2 Platform

 email: [EMAIL PROTECTED]
mobile: +61 4 0290 1228

"The key ingredients of success are a crystal-clear goal,
a realistic attack plan to achieve that goal,
and consistent, daily action to reach that goal."

Steve Maguire, "Debugging the Development Process".

LISAsoft
http://www.lisasoft.com/

Adelaide                  Sydney
--------------------      ------------------------
38 Greenhill Rd           Level 3, 228 Pitt Street
Wayville S.A. 5034        Sydney NSW 2000
Australia                 Australia

PH  +61 8 8272 1555       PH  +61 2 9283 0877
FAX +61 8 8271 1199       FAX +61 2 9283 0866
--------------------      ------------------------

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to