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.
How can I use container-managed transaction?
Can you give some ideas, what should I configure or what the code should be like?
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
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?
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 ;)
I managed to find in a test case in jboss portal sources a class that retrieves the transaction like that:
but when I run this code I get
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.