Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Calling external methods from within a transaction

39 views
Skip to first unread message

Pavanapuresan

unread,
Aug 13, 2001, 4:42:30 AM8/13/01
to
hi all,
I had posted this query earlier, but haven't received a clear response yet,
so im posting it again in its entirety.
Im using WAS 3.5.4 on NT4.6 with DB2 7.1 and VAJ 3.5.3

I have an add method whose skeleton im reproducing below:

public boolean add ( parameters ) {
try {
UserTransaction utx = (UserTransaction)
ctx.lookup("jta/usertransaction");
// beginning transaction
utx.begin();

...........insertion into tables A and B......

if ( condition ) {
insertIntoAnotherTableC( parameters );
}

// committing transaction
utx.commit();

} catch (Exception e) {
utx.rollback();
}

}

Now when the condition is false, the insertion into the tables A and B goes
through fine. However, when the condition is true, it calls the method
insertIntoAnotherTableC() . This method, inserts a few records into table C
with some values passed to the add method. The method
insertIntoAnotherTableC, uses entity
beans to insert records into the table C. And the transaction attribute of
those entity beans is TX_SUPPORTS. I wanted to know, if the entity beans are
creating their own transactions and committing them before the user
transaction's commit? Just a shot in the dark..
When this method is called, the commit fails. Rollback exceptions are
thrown.
The important lines of the exception are as follows:

javax.transaction.RollbackException
at java.lang.Throwable.<init>(Throwable.java:84)
at java.lang.Exception.<init>(Exception.java:35)
at javax.transaction.RollbackException.<init>(RollbackException.java:36)
at
com.ibm.ejs.jts.jta.UserTransactionImpl.commit(UserTransactionImpl.java:188)
at
com.mki.ebanking.beans.bankusers.BankusersManagerBean.add(BankusersManagerBe
an.java:282)
at
com.mki.ebanking.beans.bankusers.EJSRemoteBankusersManager.add(EJSRemoteBank
usersManager.java:35)
............................................................................
...................

java.lang.IllegalStateException: org.omg.CosTransactions.NoTransaction
at java.lang.RuntimeException.<init>(RuntimeException.java:49)
at java.lang.IllegalStateException.<init>(IllegalStateException.java:47)
at
com.ibm.ejs.jts.jta.UserTransactionImpl.rollback(UserTransactionImpl.java:23
8)
at
com.mki.ebanking.beans.bankusers.BankusersManagerBean.add(BankusersManagerBe
an.java:285)
at
com.mki.ebanking.beans.bankusers.EJSRemoteBankusersManager.add(EJSRemoteBank
usersManager.java:35)
............................................................................
...........................

I also found out that once i set the autocommit property of the connection
to false, it appeared to work fine. It enters records into tables A and B
but it fails again at the method - without entering any records in table C -
with the following exception :

java.lang.IllegalStateException: Connection is dirty: cannot join global
transaction
at java.lang.RuntimeException.<init>(RuntimeException.java:49)
at java.lang.IllegalStateException.<init>(IllegalStateException.java:47)
at com.ibm.ejs.cm.pool.ConnectO.enlist(ConnectO.java(Compiled Code))
at
com.ibm.ejs.cm.pool.OnePhaseConnectO.enlist(OnePhaseConnectO.java(Compiled
Code))
at com.ibm.ejs.cm.pool.ConnectO.enlist(ConnectO.java(Compiled Code))
at com.ibm.ejs.cm.pool.ConnectO.preInvoke(ConnectO.java(Compiled Code))
at com.ibm.ejs.cm.proxy.Proxy.__preInvoke(Proxy.java(Compiled Code))
at com.ibm.ejs.cm.proxy.Proxy.__preInvoke(Proxy.java(Compiled Code))
...............................


Now my questions are:

1. Why does it fail?
2. The second part of the exception is a NoTransaction exception. Isnt
websphere able to maintain the transaction across method invocations?
3. This works fine in Weblogic 5.1. So is it a problem with WAS 3.5.4 (EJB
1.0)? Will it work in WAS 4.0?
4. Is there any workaround for this?

If anybody does know anything about this, i require your help ASAP. PLEASE
get back immediately. I need to solve this problem before i can continue
working on anything else.

Thanks and regards.

Pavan


Pavanapuresan

unread,
Aug 13, 2001, 9:55:31 AM8/13/01
to
Hi all,
This is urgent. If anybody has any idea about this problem, i request you to
put forward any ideas you might have. I cant proceed, without this being
resolved.

Thanks

regards

Pavan.

Pavanapuresan <pav...@midas-kapiti.com> wrote in message
news:9l83ve$1dsk$1...@news.boulder.ibm.com...

David Artus

unread,
Aug 13, 2001, 4:54:56 PM8/13/01
to

Wish I could help ...

Your diaganostics indicate that, as expected if you have auto commit
on then there's no transaction for C to play in. You're correct in
turning off auto commit. I don't know for sure what the other message means
but my guess is that perhaps the original A,B transaction was operatind
as one user and hence a connection was obatined for that user
and the EJB is configured to run as someone else?

Pavanapuresan

unread,
Aug 14, 2001, 4:50:44 AM8/14/01
to
Thanks David, But I have a couple of doubts with your post :
1. Even if i turn auto-commit off, records are no tinserted in to table C.
Instead, it fails with the following exception:

java.lang.IllegalStateException: Connection is dirty: cannot join global
transaction
So turning autocommit off hasn't solved the problem.
2. How are the transactions and EJBs configured with any particular user? Im
not sure i understood this bit in your post. I thought that specific users
were tied in only with database schemas and that too only in DB2. Could u
clarify this also please.

Thanks

Pavan

David Artus <art...@nospamuk.ibm.nospamcom> wrote in message
news:3B783EA0...@nospamuk.ibm.nospamcom...

David Artus

unread,
Aug 14, 2001, 8:43:52 AM8/14/01
to

Pavanapuresan wrote:

> Thanks David, But I have a couple of doubts with your post :
> 1. Even if i turn auto-commit off, records are no tinserted in to table C.
> Instead, it fails with the following exception:
> java.lang.IllegalStateException: Connection is dirty: cannot join global
> transaction

Yes, this is the problem you need to solve.

>
> So turning autocommit off hasn't solved the problem.
> 2. How are the transactions and EJBs configured with any particular user? Im
> not sure i understood this bit in your post. I thought that specific users
> were tied in only with database schemas and that too only in DB2. Could u
> clarify this also please.

When you get a connection from the pool (you are using websphere's
data sources?) you can specify username and password.

You can also define user names and passwords for EJBs.

I was wondering whether you had different values for each.

Are your EJBs and your other code all running in the same JVM?

Afraid that I cannot find you an aswer. Suggest you contact IBM
support.


Paul Ilechko

unread,
Aug 14, 2001, 8:55:46 AM8/14/01
to
Why are you creating a user transaction ? Where is this code snippet running, in
an EJB method ? If so, why not make it TX_REQUIRED instead of bean managed ?

Pavanapuresan

unread,
Aug 14, 2001, 2:37:17 PM8/14/01
to
OK thanks anyway, David, for the info. And,no i use the same userid and
password for the EJBs and the data sources. Could u tell me an email address
at which i can contact IBM Support? Im afraid i dont know the first thing
about the procedures involved in asking IBM Support for help.

And Paul, when this code was developed for Weblogic, there was a need to
insert records into more than one table, in many modules. We tried out with
many of the TX_ attributes, but we found out that, if an exception occurred
between insertion of records into table A and table B, the inserts into
table A didnt get rolled back. So we decided to use UserTransactions and set
the transaction attribute of all the beans as TX_SUPPORTS.
Yes, this code snippet is running in an EJB Method.
Making it TX_REQUIRED results in another set of exceptions, which i have
posted about. Then, Im not able to use user transactions. It fails at the
line UserTransaction.begin(). Thats the reason why i changed them to
TX_BEAN_MANAGED.

David Artus <art...@nospamuk.ibm.nospamcom> wrote in message

news:3B791D07...@nospamuk.ibm.nospamcom...

Paul Ilechko

unread,
Aug 14, 2001, 3:46:19 PM8/14/01
to
If you make the transaction bean managed you have to remove your user
transaction statements, otherwise you are in violation of the EJB spec.

Paul Ilechko

unread,
Aug 14, 2001, 3:47:15 PM8/14/01
to
Sorry, I meant to say if you make your transaction container managed ...

Pavanapuresan

unread,
Aug 15, 2001, 4:31:28 AM8/15/01
to
Im sorry, i too wasnt probably very clear in my post. I meant that my
session beans have a transaction attribute of TX_BEAN_MANAGED but the entity
beans have a trans. attrib. of TX_SUPPORTS. So the use of user transactions
in the session beans is ok i think.

regards

Pavan


Paul Ilechko <paul.i...@bms.com> wrote in message
news:3B798043...@bms.com...

Paul Ilechko

unread,
Aug 15, 2001, 9:12:00 AM8/15/01
to
Did you try running your session beans as TX_REQUIRED and taking out the user
transactions ?

Pavanapuresan

unread,
Aug 16, 2001, 9:22:30 AM8/16/01
to
No go Paul. I tried that, but i get the following exceptions:

javax.transaction.TransactionRolledbackException: CORBA
TRANSACTION_ROLLEDBACK 0 No; nested exception is:
org.omg.CORBA.TRANSACTION_ROLLEDBACK:
com.ibm.websphere.csi.CSITransactionRolledbackException:
at java.io.IOException.<init>(IOException.java:49)
at java.rmi.RemoteException.<init>(RemoteException.java:58)
at com.ibm.websphere.csi.CSIException.<init>(CSIException.java:30)
at
com.ibm.websphere.csi.CSITransactionRolledbackException.<init>(CSITransactio
nRolledbackException.java:32)
at com.ibm.ejs.csi.TranStrategy.commit(TranStrategy.java:185)
at com.ibm.ejs.csi.TranStrategy.postInvoke(TranStrategy.java:59)
at
com.ibm.ejs.csi.TransactionControlImpl.postInvoke(TransactionControlImpl.jav
a:407)
at com.ibm.ejs.container.EJSContainer.postInvoke(EJSContainer.java:1752)
............................................................................
............
minor code: 0 completed: No
org.omg.CORBA.TRANSACTION_ROLLEDBACK:
com.ibm.websphere.csi.CSITransactionRolledbackException:
at java.io.IOException.<init>(IOException.java:49)
at java.rmi.RemoteException.<init>(RemoteException.java:58)
at com.ibm.websphere.csi.CSIException.<init>(CSIException.java:30)
at
com.ibm.websphere.csi.CSITransactionRolledbackException.<init>(CSITransactio
nRolledbackException.java:32)
at com.ibm.ejs.csi.TranStrategy.commit(TranStrategy.java:185)
at com.ibm.ejs.csi.TranStrategy.postInvoke(TranStrategy.java:59)
at
com.ibm.ejs.csi.TransactionControlImpl.postInvoke(TransactionControlImpl.jav
a:407)
at com.ibm.ejs.container.EJSContainer.postInvoke(EJSContainer.java:1752)
............................................................................
..............
minor code: 0 completed: No


at java.lang.RuntimeException.<init>(RuntimeException.java:49)

at org.omg.CORBA.SystemException.<init>(SystemException.java:51)
at
org.omg.CORBA.TRANSACTION_ROLLEDBACK.<init>(TRANSACTION_ROLLEDBACK.java:71)
at
org.omg.CORBA.TRANSACTION_ROLLEDBACK.<init>(TRANSACTION_ROLLEDBACK.java:50)
at java.lang.reflect.Constructor.newInstance(Native Method)
at javax.rmi.CORBA.Util.copyObject(Util.java:804)


Thanks and regards,

Pavan

Paul Ilechko <paul.i...@bms.com> wrote in message

news:3B7A7520...@bms.com...

sanjay

unread,
Aug 16, 2001, 10:58:06 AM8/16/01
to
Make sure that you are using same isolation level for both session and entity
bean methods.

Thanks,
Sanjay

Pavanapuresan

unread,
Aug 17, 2001, 6:25:43 AM8/17/01
to
I am! The isolation level for ALL my beans (both session and entity) is
TRANSACTION_READ_COMMITTED.

Thanks and regards

Pavan


sanjay <Sanjay....@stasco.com> wrote in message
news:3B7BDF7D...@stasco.com...

0 new messages