Hi Aaron,

Aaron Mulder wrote:
AM> On Wed, 6 Dec 2000, Oleg Nitz wrote:
>> con2 = ds2.getConnection();
>> ut = ejbContext.getUserTransaction();
>> ut.begin();
>>
>> don't enlist the resource to the transaction, see XAConnectionFactory:
>>
>>     public Object prepareObject(Object pooledObject) {
>>        ...
>>             if(tm.getStatus() != Status.STATUS_NO_TRANSACTION) {
>>                 ...
>>                 trans.enlistResource(res);

AM>         We've covered this in detail before.  Check the archives.
I remember the discussion on CMT and resources that are held by the
bean between method invocations. All agreed that that is a bad
practice and there are more important things to do.
Okay, but I speak about BMT, and several sequential transactions for
the same resource in the same method is absolutely legal thing -
this is what BMT is usually used for.

AM> I can't remember the exact compelling argument, but I think it was
AM> challenging to determine which resources should be associated with
AM> a transaction if you start a transaction after the resources have
AM> been started.
I wouldn't like to discuss this in general now, but for BMT the answer
is clear for me: all resources that was got by the bean should listed
in EnterpriseContext (or in the environment of bean JNDI Context -
that might me easier to implement), when UserTransaction begins, it
enlists all that resources. BTW, EnterpriseContext should keep
reference to the UserTransaction instance and return in from
getUserTransaction until the completion of the transaction
(11.3.3 of EJB 1.1 specification runs: "If a transaction has not
been completed by the end of a business method, the Container retains
the association between the transaction and the instance across
multiple client calls until the instance eventually completes the
transaction").

AM> Where in the spec does it insist that you should be
AM> able to start a transaction after accessing a resource and have
AM> the transaction apply to the resource?
Well, I gave references in the previous message, but I can repeat:
11.3.3 of EJB 1.1 specification gives several examples for BMT,
the first example contains the following code:

...
// obtain con1 object and set it up for transactions
ds1 = (javax.sql.DataSource)
initCtx.lookup(�java:comp/env/jdbcDatabase1�);
con1 = ds1.getConnection();
stmt1 = con1.createStatement();

// obtain con2 object and set it up for transactions
ds2 = (javax.sql.DataSource)
initCtx.lookup(�java:comp/env/jdbcDatabase2�);
con2 = ds2.getConnection();
stmt2 = con2.createStatement();

//
// Now do a transaction that involves con1 and con2.
//
ut = ejbContext.getUserTransaction();

// start the transaction
ut.begin();

// Do some updates to both con1 and con2. The Container
// automatically enlists con1 and con2 with the transaction.
...


AM> And what does it say should be done with work performed on the
AM> resource before the transaction was started?
AFAIK it says nothing about that. It just says that
"All updates to the resource managers between the
UserTransaction.begin() and UserTransaction.commit() methods are
performed in a transaction".

Best regards,
 Oleg 



Reply via email to