Announcement Announcement Module
Collapse
No announcement yet.
Transactions in service layer Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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.

    Comment


    • #3
      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.

      Comment


      • #4
        Did you get any resolution to this

        Did you get any resolution to this

        Comment


        • #5
          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.

          Comment


          • #6
            Yep, works fine. Thanks a lot!!!

            Comment

            Working...
            X