-
30. Re: Transactional propagation types
asookazian Aug 27, 2009 1:33 AM (in response to asookazian)Ok thx.
Here's what I'm doing. NOTE: the insertion of the records was successful today @ 4:08PM even though the web service threw an exception (I'm doing this on purpose to test the scenario). This is considered a passed test.
Now, the inserts to local db don't work. I even did a local history compare in Eclipse and no dice.
I'm getting this:
javax.persistence.TransactionRequiredException: No active JTA transaction on joinTransaction call
When I do this:
public void apply() { progressBarWebService.startProcess(); progressBarLocalDB.startProcess(); //get a reference to yourself if using JavaBean component, this did not work... EquipmentProcessingViewAction equipmentProcessingView = (EquipmentProcessingViewAction) Component.getInstance("equipmentProcessingView"); equipmentProcessingView.insertStatusAndErsNote(); }
@Transactional public void insertStatusAndErsNote(){ //we need to insert into two tables: EquipmentRecoveryStatusChangeLog and EquipmentNotes try { entityManager.joinTransaction(); Long equipmentRecoveryId = currentlySelectedEquipmentBean.getEquipmentRecoveryId(); EquipmentRecovery equipmentRecovery = entityManager.find(EquipmentRecovery.class, equipmentRecoveryId); int equipmentStatusId = selectedListValueForNewStatus.getCode(); EquipmentStatus equipmentStatus = entityManager.find(EquipmentStatus.class, equipmentStatusId); ... persist() occurs down here, etc.}
I also noticed that if I add the @Transactional(TransactionPropagationType.NEVER) to the apply() method, it's not throwing that exception anymore. Very strange, I did not change components.xml.
There is currently no @Transactional at the class level.
-
31. Re: Transactional propagation types
asookazian Aug 27, 2009 1:35 AM (in response to asookazian)
Arbi Sookazian wrote on Aug 27, 2009 01:33:
I also noticed that if I add the @Transactional(TransactionPropagationType.NEVER) to the apply() method, it's not throwing that exception anymore. Very strange, I did not change components.xml.
There is currently no @Transactional at the class level.To be clear: by
that exception
I'm referring to the exception I was getting when I originally added @Transactional(TransactionPropagationType.NEVER) to the apply() method:Caused by: java.lang.IllegalStateException: Transaction active on call to NEVER method
I am not see that exception with NEVER. So that means to me that the
mysterious
existing tx is no longer alive/active when apply() is executed? -
32. Re: Transactional propagation types
luxspes Aug 27, 2009 2:00 AM (in response to asookazian)
Stuart Douglas wrote on Aug 27, 2009 01:07:
If the em is created when no transaction is active then it is not associated with a transaction. When you create a JTA transaction you need to call entityManager.joinTransaction() to associate it with the transaction (this is only for jta, resource local is different).AFAIK entityManager.joinTransaction is exactly what he does NOT want to do, what he needs in an entity manager running in its own parallel and independant transaction
-
33. Re: Transactional propagation types
luxspes Aug 27, 2009 2:02 AM (in response to asookazian)
Arbi Sookazian wrote on Aug 27, 2009 01:33:
I am not see that exception with NEVER. So that means to me that themysterious
existing tx is no longer alive/active when apply() is executed?I guess that is right, and that also means you can define you transactional methods in another bean that does have @Transactional and call them one after the other, so that they execute in 2 different sequential transactions
-
34. Re: Transactional propagation types
swd847 Aug 27, 2009 2:18 AM (in response to asookazian)You have three options:
- Run this as an async method: That way it is associated with a new thread and a new transaction.
- Move to EJB3 so you can use REQUIRES_NEW
- Look up the JTA TransactionManager and manually suspend and resume your transactions.
I would go for option 1. -
35. Re: Transactional propagation types
swd847 Aug 27, 2009 2:24 AM (in response to asookazian)
I guess that is right, and that also means you can define you transactional methods in another bean that does have @Transactional and call them one after the other, so that they execute in 2 different sequential transactionsAs long as the bean that you are calling from is not marked @Transactional (otherwise you will still be in the callers transaction).
-
36. Re: Transactional propagation types
asookazian Aug 27, 2009 7:17 PM (in response to asookazian)
Arbi Sookazian wrote on Aug 27, 2009 01:33:
Ok thx.
Here's what I'm doing. NOTE: the insertion of the records was successful today @ 4:08PM even though the web service threw an exception (I'm doing this on purpose to test the scenario). This is considered a passed test.Sorry, I lied. The time of update for the record was 4:08PM but the date was not yesterday. There have been no inserts into the tables since 08-24-09.
-
37. Re: Transactional propagation types
asookazian Aug 27, 2009 7:20 PM (in response to asookazian)
Stuart Douglas wrote on Aug 27, 2009 02:18:
- Run this as an async method: That way it is associated with a new thread and a new transaction.How can I do this?
Marks a method as an asynchronous method, to be dispatched by the EJB3 TimerService.http://docs.jboss.org/seam/2.0.1.CR1/api/org/jboss/seam/annotations/async/Asynchronous.html
So if I annotate my private methods using @Asynchronous will that be good enough or what?
-
38. Re: Transactional propagation types
asookazian Aug 27, 2009 7:27 PM (in response to asookazian)So I tried the following:
@Transactional @Asynchronous public void insertStatusAndErsNote(){...}
And got:
10:24:40,206 ERROR [EquipmentProcessingViewAction] error occurred: javax.persistence.TransactionRequiredException: no transaction is in progress
when the entityManager.flush() executes.
that's without:
entityManager.joinTransaction();
which probably won't make a difference if there is not an active tx to join.
-
-
40. Re: Transactional propagation types
asookazian Aug 27, 2009 8:26 PM (in response to asookazian)Ok, so in order to proceed with my other coding (I can't believe this took this long and I did not solve my problem), I turned back on global tx's in components.xml:
<!-- <core:init debug="@debug@" jndi-pattern="@jndiPattern@" transaction-management-enabled="false"/> --> <core:init debug="@debug@" jndi-pattern="@jndiPattern@"/>
Now there is an active tx when the apply() method is invoked, and the inserts to local db tables are successful again.
Now here's the interesting part. The two inserts and one update are committing first. Then the web service code is throwing an exception (I'm using wrong credentials on purpose to see how the system behaves when there's an exception in the web service call):
11:08:44,486 ERROR [ProgressBarWebServiceAction] ProgressBarWebServiceAction.callWebService(): caught CoxWseWebServiceException: com.cox.ers.webservice.client.CoxWseWebServiceException: FaultType: Server.generalException, FaultName: null
Now because both private methods are invoked from the public void apply(), which is apparently part of an active tx, I would have expected the inserts and update to local db to rollback when apply() completes.
so what's the explanation now? why were the local CRUD operations successful if there's a tx wrapped around the entire unit of work?
public void apply() { callWebService(); insertStatusAndErsNote(); }
-
41. Re: Transactional propagation types
asookazian Aug 27, 2009 8:36 PM (in response to asookazian)Most likely because I'm catching the exception and not throwing it to the client?
@Name("progressBarWebService") @ProfilingThisClass @Scope(ScopeType.CONVERSATION) public class ProgressBarWebServiceAction { ... private boolean callWebService(){ try{ return webServiceCaller.addCustomerComments(); } catch(CoxWseWebServiceException wse){ log.error("ProgressBarWebServiceAction.callWebService(): caught CoxWseWebServiceException: ", wse); facesMessages.add("Error occurred during add customer comment web service call."); return false; } catch(Exception e){ log.error("ProgressBarWebServiceAction.callWebService(): caught Exception: ", e); facesMessages.add("Error occurred during add customer comment web service call."); return false; } } ... }