Results 1 to 9 of 9

Thread: Implementing jta callbacks

  1. #1
    Join Date
    Jan 2007
    Posts
    11

    Default 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. #2
    Join Date
    Jan 2007
    Posts
    11

    Default 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");

    }

    }

  3. #3
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    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

  4. #4
    Join Date
    Jan 2007
    Posts
    11

    Default

    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

  5. #5
    Join Date
    Jun 2005
    Posts
    4,230

    Default

    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?

  6. #6
    Join Date
    Jan 2007
    Posts
    11

    Default

    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.

  7. #7
    Join Date
    Jan 2007
    Posts
    11

    Default

    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

  8. #8
    Join Date
    Jun 2005
    Posts
    4,230

    Default

    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.

  9. #9
    Join Date
    Jan 2007
    Posts
    11

    Default

    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

Posting Permissions

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