Results 1 to 6 of 6

Thread: Transactions in service layer

  1. #1

    Default Transactions in service layer

    I have declarative transaction defined in the service layer as an example below.

    <!-- data tracking service -->
    <bean id="myDataTrackingService" parent="txProxyTemplate" >
    <property name="target">
    <bean class="com.xxx.service.DataTrackingServiceImpl"></bean>
    </property>
    <property name="transactionAttributes">
    <props>
    <prop key="find*">PROPAGATION_REQUIRED,-Exception</prop>
    <prop key="save*">PROPAGATION_REQUIRED,-Exception</prop>
    <prop key="reprocessEDD">PROPAGATION_REQUIRED,-Exception</prop>
    </props>
    </property>
    </bean>

    I have 3 services:

    Service 1:
    Insert();
    Update();

    Service 2:
    Insert();
    Update();

    Service 3:
    service1.Insert();
    service2.update();

    I am not quite sure how to implement transaction control in service 3 as service1 & service2 have individual transactions defined.

    Is it possible to do something like this?? Any help is appreciated..

  2. #2
    Join Date
    Aug 2004
    Location
    San Mateo, CA
    Posts
    1,265

    Default

    It depends on propagation settings. If you want you can have Service 1 and Service 2 transactional if used independently, but execute within an encompassing transaction from Service 3 if one exists. PROPAGATION_REQUIRED is what you want. (The concept is the same in Spring and EJB CMT.) This will use the current tx scope if one exists, but create a new one if none does.
    Rod Johnson - GM, SpringSource Division, VMware
    http://www.springsource.com
    Spring From the Source

  3. #3

    Default

    If you want you can have Service 1 and Service 2 transactional if used independently, but execute within an encompassing transaction from Service 3 if one exists.

    Didnt quite understand this.. If I have independent transactions defined for Service1 & Service2 as these are used in many places.. and
    If I have a transaction defined for Service 3,

    Service 3:
    service1.Insert(); --------OK
    service2.update(); --------Fails

    How do I rollback the insert?? Could you give me a example, would really appreciate the same.

    Thanks for the quick reply.

  4. #4
    Join Date
    Sep 2004
    Posts
    346

    Default Did you get any resolution to this

    Did you get any resolution to this

  5. #5
    Join Date
    Aug 2004
    Location
    San Mateo, CA
    Posts
    1,265

    Default

    If I have independent transactions defined for Service1 & Service2 as these are used in many places.. and
    If I have a transaction defined for Service 3 (which calls Service1 & Service2)
    Service1 and Service2 will execute in an encompassing transaction created for Service3, with PROPAGATION_REQUIRED. The INSERT will be rolled back automatically.
    Rod Johnson - GM, SpringSource Division, VMware
    http://www.springsource.com
    Spring From the Source

  6. #6

    Default

    Yep, works fine. Thanks a lot!!!

Similar Threads

  1. Business Service layer ?
    By ambeth in forum Web
    Replies: 0
    Last Post: Sep 5th, 2005, 06:13 AM
  2. One ApplicationContext per Layer problem...
    By Alwin in forum Container
    Replies: 2
    Last Post: Jul 7th, 2005, 10:49 PM
  3. User information in the service layer
    By luxaeterna in forum Architecture
    Replies: 5
    Last Post: Feb 24th, 2005, 11:14 PM
  4. EJB service layer non-OO / Anemic Domain Model
    By Aro in forum Architecture
    Replies: 0
    Last Post: Jan 15th, 2005, 07:10 AM
  5. Creating a proper service layer?
    By infectedrhythms in forum Architecture
    Replies: 5
    Last Post: Jan 5th, 2005, 06:32 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •