-
1. Re: UserModule transaction problem
soshah Oct 23, 2006 10:05 AM (in response to alexandru30043004)You should be able to run this operation within the scope of a transaction and have both operations work as a single unit
You can do this programmatically kind of like this for a hint:UserTransaction tx = NamingContext.lookup("javax.transaction.UserTransaction"); tx.begin(); //your code here addMyUser userModule.addUser tx.commit();
Even more elegant is using container-managed transaction using EJB 3.0 or something like that.
I have personally used it with EJB 3.0 container managed transactions and it works just fine.
Thanks
Sohil -
2. Re: UserModule transaction problem
alexandru30043004 Oct 23, 2006 11:10 AM (in response to alexandru30043004)How can I use container-managed transaction?
Can you give some ideas, what should I configure or what the code should be like?
Thanks. -
3. Re: UserModule transaction problem
soshah Oct 23, 2006 11:19 AM (in response to alexandru30043004)For using container managed transactions look at
EJB3.0. Your business controller logic looks simple and the transaction is managed by the container within which your bean runs.
If EJB3.0 is not part of your architecture, use programmatic transaction management like the code snippet I submitted in the earlier post
Thanks
Sohil -
4. Re: UserModule transaction problem
alexandru30043004 Oct 23, 2006 2:02 PM (in response to alexandru30043004)
I've tried using
UserTransaction tx = (UserTransaction) new InitialContext().lookup("javax.transaction.UserTransaction");
but tx is null, doesn't retrieve an object. Maybe the key "javax.transaction.UserTransaction" is wrong. Can you please tell me where should I look for the right key, in what xml file?
Thanks. -
5. Re: UserModule transaction problem
mholzner Oct 23, 2006 2:17 PM (in response to alexandru30043004)By default the transaction is suspended before the call to the portlet container. You need to flag your portlet to require a transaction in the portal object descriptor. There are examples for that in the standard descriptor examples.
After flagging your portlet there, you should be able to lookup the UserTransaction.... (in theory ;) -
6. Re: UserModule transaction problem
alexandru30043004 Oct 23, 2006 2:29 PM (in response to alexandru30043004)
I managed to find in a test case in jboss portal sources a class that retrieves the transaction like that:
(UserTransaction)new InitialContext().lookup("UserTransaction");
but when I run this code I get
Error org.jboss.tm.usertx.client.ServerVMClientUserTransaction
ErrorType java.lang.ClassCastException
Stacktrace ...
Any ideea? -
7. Re: UserModule transaction problem
alexandru30043004 Oct 23, 2006 2:41 PM (in response to alexandru30043004)
This is very strange because I found the class org.jboss.tm.usertx.client.ServerVMClientUserTransaction and I looked at it's signature and it implements javax.transaction.UserTransaction so by casting to javax.transaction.UserTransaction should not throw ClassCastException.
I'm realy lost. Can anyone help me please.
Thanks -
8. Re: UserModule transaction problem
andyd Oct 23, 2006 5:47 PM (in response to alexandru30043004)Take a look at this to see if it helps.
Andy.
http://wiki.jboss.org/wiki/Wiki.jsp?page=UTFactoryLookupFailed