Hi,
I have developed several custom services and I encounter a problem with transactions. My service is calling other services and I notice that when a first service successed, but a second failed, the data of the first service has not been rolled back. Example : - First, I call "createPersonAndUserLogin" using dispatcher.runSync - Second, I call "createPartyRole" using dispatcher.runSync The second call failed because I didn't provide all parameters, but the party created in the first call is still there. Is there a way to avoid this, to have a transaction covering all runSync calls ? Thanks, Cimballi |
Hi Cimballi,
TransactionUtil.rollback(boolean beganTransaction, String causeMessage, Throwable causeThrowable) will be your friend here. On passing beganTrasaction value to tru it will rollback the current thread transactions. Rishi Solanki Enterprise Software Developer HotWax Media Pvt. Ltd. On Thu, Nov 12, 2009 at 5:19 AM, Cimballi <[hidden email]> wrote: > Hi, > > I have developed several custom services and I encounter a problem > with transactions. > My service is calling other services and I notice that when a first > service successed, but a second failed, the data of the first service > has not been rolled back. > Example : > - First, I call "createPersonAndUserLogin" using dispatcher.runSync > - Second, I call "createPartyRole" using dispatcher.runSync > > The second call failed because I didn't provide all parameters, but > the party created in the first call is still there. > > Is there a way to avoid this, to have a transaction covering all runSync > calls ? > > Thanks, > > Cimballi > |
Hey Rishi, thanks for the answer.
To be more clear, I am calling my service via RMI. I didn't specify any specific configuration in the service XML file, but I suppose that my service is encapsulated in a transaction, no ? And so I would expect the transaction being rolled back by the dispatcher as my service returns "error". Shouldn't it work this way ? Cimballi On Thu, Nov 12, 2009 at 7:18 AM, Rishi Solanki <[hidden email]> wrote: > Hi Cimballi, > TransactionUtil.rollback(boolean beganTransaction, String causeMessage, > Throwable causeThrowable) > will be your friend here. On passing beganTrasaction value to tru it will > rollback the current thread transactions. > > Rishi Solanki > Enterprise Software Developer > HotWax Media Pvt. Ltd. > > > On Thu, Nov 12, 2009 at 5:19 AM, Cimballi <[hidden email]> wrote: > >> Hi, >> >> I have developed several custom services and I encounter a problem >> with transactions. >> My service is calling other services and I notice that when a first >> service successed, but a second failed, the data of the first service >> has not been rolled back. >> Example : >> - First, I call "createPersonAndUserLogin" using dispatcher.runSync >> - Second, I call "createPartyRole" using dispatcher.runSync >> >> The second call failed because I didn't provide all parameters, but >> the party created in the first call is still there. >> >> Is there a way to avoid this, to have a transaction covering all runSync >> calls ? >> >> Thanks, >> >> Cimballi >> > |
In reply to this post by Cimballi
On Nov 12, 2009, at 12:49 AM, Cimballi wrote: > Hi, > > I have developed several custom services and I encounter a problem > with transactions. > My service is calling other services and I notice that when a first > service successed, but a second failed, the data of the first service > has not been rolled back. > Example : > - First, I call "createPersonAndUserLogin" using dispatcher.runSync > - Second, I call "createPartyRole" using dispatcher.runSync > > The second call failed because I didn't provide all parameters, but > the party created in the first call is still there. The reason is in the service definition for "createPersonAndUserLogin": <service name="createPersonAndUserLogin" engine="simple" require-new-transaction="true" location="component://party/script/org/ofbiz/party/party/PartySimpleMethods.xml" invoke="createPersonAndUserLogin" auth="false"> <description>Create a Person and UserLogin</description> <implements service="createUserLogin"/> <auto-attributes entity-name="Person" mode="IN" include="nonpk" optional="true"/> <auto-attributes entity-name="Party" mode="IN" include="nonpk" optional="true"/> <attribute name="partyId" type="String" mode="INOUT" optional="true" entity-name="Person"/> <attribute name="newUserLogin" type="Map" mode="OUT" optional="false"/> </service> This service is executed in its own transaction because of the attribute: require-new-transaction="true" Jacopo > > Is there a way to avoid this, to have a transaction covering all runSync calls ? > > Thanks, > > Cimballi |
Ok ! Thanks a lot Jacopo !
Cimballi On Thu, Nov 12, 2009 at 10:07 AM, Jacopo Cappellato <[hidden email]> wrote: > > On Nov 12, 2009, at 12:49 AM, Cimballi wrote: > >> Hi, >> >> I have developed several custom services and I encounter a problem >> with transactions. >> My service is calling other services and I notice that when a first >> service successed, but a second failed, the data of the first service >> has not been rolled back. >> Example : >> - First, I call "createPersonAndUserLogin" using dispatcher.runSync >> - Second, I call "createPartyRole" using dispatcher.runSync >> >> The second call failed because I didn't provide all parameters, but >> the party created in the first call is still there. > > The reason is in the service definition for "createPersonAndUserLogin": > > <service name="createPersonAndUserLogin" engine="simple" require-new-transaction="true" > location="component://party/script/org/ofbiz/party/party/PartySimpleMethods.xml" invoke="createPersonAndUserLogin" auth="false"> > <description>Create a Person and UserLogin</description> > <implements service="createUserLogin"/> > <auto-attributes entity-name="Person" mode="IN" include="nonpk" optional="true"/> > <auto-attributes entity-name="Party" mode="IN" include="nonpk" optional="true"/> > <attribute name="partyId" type="String" mode="INOUT" optional="true" entity-name="Person"/> > <attribute name="newUserLogin" type="Map" mode="OUT" optional="false"/> > </service> > > This service is executed in its own transaction because of the attribute: > > require-new-transaction="true" > > Jacopo > >> >> Is there a way to avoid this, to have a transaction covering all runSync calls ? >> >> Thanks, >> >> Cimballi > > |
Free forum by Nabble | Edit this page |