Announcement Announcement Module
Collapse
No announcement yet.
Implementing jta callbacks Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Implementing jta callbacks

    Hello,

    I was wondering if someone could describe how to implement this or maybe or point me to documentation on the subject.

    Doing this in EJB was quite simple, just implement SessionSynchronization in your Session bean and container will call afterBegin() beforeCompletion() callback metionds.

    So far I am unable to implement the same in Spring.

    Any help would be appricated.

    Thanks

  • #2
    Implementing jta callbacks

    I have tried to implement TransactionSynchronization for bean that is executed in transaction. However, still jta callbacks (beforeCompletion(), afterCommit()) are not called.

    Am i missing additional confirguration?

    Thanks.




    <bean id="parentServiceWithTxn" abstract="true"
    class="org.springframework.transaction.interceptor .TransactionProxyFactoryBean">
    <property name="transactionManager" ref="transactionManager"/>
    <property name="transactionAttributes">
    <props>
    <prop key="*">PROPAGATION_REQUIRED, timeout_300</prop>
    </props>
    </property>
    </bean>



    <bean id="service" parent="parentServiceWithTxn">
    <property name="target">
    <bean class="com.ServiceImpl">
    <property name="baseDao" ref="baseDao"/>

    <property name="jdbcTemplate" ref="jdbcTemplate"/>

    </bean>
    </property>
    </bean>



    public class ServiceImpl implements TransactionSynchronization {

    public void beforeCompletion(){
    System.out.print("beforeCompletion");

    }

    public void afterCommit(){
    System.out.print("afterCommit");

    }

    }

    Comment


    • #3
      Let me first say, I can't claim to have any knowledge on this. Did a quick search for spring jta callback, one of the results was. Have you tried the same?

      http://www.springframework.org/docs/...onAdapter.html

      Comment


      • #4
        Thank you for the response.

        Not sure how to use the class. Checked the link below, it does not have information.

        http://www.springframework.org/docs/...onAdapter.html

        Comment


        • #5
          You have to register the synchronization with the transaction somehow. You normally would call TransactionSynchronizationManager.registerSynchron ization, once the transaction has started (so if you put it in a POJO, you can then only test it with a transactional test). Is that what is needed here, or did I miss something?

          Comment


          • #6
            Thank you for the response.

            All we need is to invoke beforeCompletion() in our service bean (which is comparable to stateless session bean in ejb). The goal here is to set authenticated user's id in jdbc connection -conn.setEndToEndMetrics(userid) for auditing.


            In ejb to achieve the behavior all i needed to do was to implement SessionSynchronization interface, and ejb container began calling beforeCompletion() and other jta callbacks.

            We are looking to implement the same in Spring.

            Comment


            • #7
              I was able to get it to work using TransactionSynchronizationManager.registerSynchron ization.

              I was wondering if the same could be achieved via configuration. The reason I am asking is that when classes are wired to each other TransactionSynchronizationManager.isSynchronizatio nActive() may be false and registration of a new synchronization may fail. I noticed that registration is possible only when

              TransactionSynchronizationManager.isSynchronizatio nActive() is true.

              Any suggestions would be wellcome.

              Thanks

              Comment


              • #8
                You could write a piece of advice that you apply after the transaction (assuming you are using declarative TX management) that would register a synchronization, then it could be configured with the correct dependency. It's not something that exists in the framework as far as I know because TransactionSynchronizationManager is mainly intended for internal use, but it sounds pretty useful.

                Comment


                • #9
                  In EJB there is afterBegin() which does not seem to exist in Spring. Is there something instead of afterBegin() in Spring that one could use to get notification right after transaction began?

                  Thanks

                  Comment

                  Working...
                  X