You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ofbiz.apache.org by Cimballi <ci...@cimballi.net> on 2009/11/12 00:49:54 UTC

Help required about custom service and transactions

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

Re: Help required about custom service and transactions

Posted by Cimballi <ci...@gmail.com>.
Ok ! Thanks a lot Jacopo !

Cimballi


On Thu, Nov 12, 2009 at 10:07 AM, Jacopo Cappellato
<ja...@hotwaxmedia.com> 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
>
>

Re: Help required about custom service and transactions

Posted by Jacopo Cappellato <ja...@hotwaxmedia.com>.
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


Re: Help required about custom service and transactions

Posted by Cimballi <ci...@gmail.com>.
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 <ri...@gmail.com> 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 <ci...@cimballi.net> 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
>>
>

Re: Help required about custom service and transactions

Posted by Rishi Solanki <ri...@gmail.com>.
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 <ci...@cimballi.net> 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
>