Forums Register Login

How to use UserTransaction in non-EJB code

+Pie Number of slices to send: Send
This is in a class that is called from within a Stateless Session bean. In this class, I'm trying to use a UserTransaction object that is created as follows (taken from Zuffoletto's book):



However, when I call tx.begin(), it throws an exception as follows:




Any ideas/suggestions/hints??

Why would this explicitly created tx, being used by one single call be colliding with an existing transaction?

Thanks for your comments. Please post to the forum.

JV

[ October 20, 2004: Message edited by: Julie Verne ]
[ October 20, 2004: Message edited by: Julie Verne ]
+Pie Number of slices to send: Send
Hi Julie,

It looks like your session bean is already running in the transaction context (is it a CMT session bean). This context gets propogated to all plain java objects that this session bean communicates with.

That's why when your plain java object tries to run in its own context (i.e. UserTransaction#begin()) your app server throws an error.

To fix the problem do one of the following:

1) make your plain java object run in the same context as the calling bean - it means that you do not need any transaction related code in your class (i.e. no reference to UserTransaction). Obviously, for this to work make sure that your bean has a transaction context.

If it is a BMT sb then:


If it is a CMT sb then ensure that your session bean's method(s) trans-attribute is one of the following: Required/RequiresNew/Mandatory. It will ensure that your session bean method always in the transaction context.


Hope it helps,



[ October 21, 2004: Message edited by: Alex Sharkoff ]
[ October 21, 2004: Message edited by: Alex Sharkoff ]
I do some of my very best work in water. Like this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 4836 times.
Similar Threads
transaction rollback or commit
Transaction timeout
Spring iBatis NullPointerException when accesing SQLMAP implemented class
Problem Calling EJB from JSP
How to convert the code of existing project to UML diagrams?
Thread Boost feature
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 08:53:39.