[jboss-user] [EJB 3.0] - Re: EJB 3 + transaction propagation
charlf
do-not-reply at jboss.com
Thu Dec 11 05:32:36 EST 2008
Hey all,
I also got this error when using the TransactionManager, which is about the same as the UserTransaction.
The problem was that I was using the the TM while it was still busy with another transaction, you have to check the status of the TM first. heres how I fixed it.
| EntityManager EM = EMF.createEntityManager();
| TransactionManager TM = (TransactionManager)ctx.lookup("java:TransactionManager");
| boolean suspended = false;
| Transaction t = null;
|
| if(TM.getStatus() == Status.STATUS_NO_TRANSACTION || TM.getStatus() == Status.STATUS_UNKNOWN)
| {
| TM.begin();
| EM.joinTransaction();
| }
| if(TM.getStatus() == Status.STATUS_ACTIVE)
| {
| suspended = true;
| t = TM.suspend();
| TM.begin();
| EM.joinTransaction();
| }
| else
| {
| throw new Exception("Transaction status invalid: "+TM.getStatus());
|
| }
|
| //Do Actual Work with DB
|
| EM.persist(Entity);
| EM.flush();
| TM.commit();
|
| if(suspended == true)
| {
| TM.resume(t);
| }
|
| TM = null;
| EM = null;
|
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4195868#4195868
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4195868
More information about the jboss-user
mailing list