Announcement Announcement Module
Collapse
No announcement yet.
JmsTemplate participating in transactions when it shouldn't Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • JmsTemplate participating in transactions when it shouldn't

    Hi!

    I've got a the following problem:

    1. a call to a service, this service uses hibernate dao which is JTA transacted
    2. this dao throws a RuntimeException due to a duplicate key - and the dao is rolled back - fine
    3. inside of this a jmstemplate is supposed to send a message (because we've noticed the duplicate key - so we want to send an event).

    So 3 is inside a JTA transaction - but SHOULD NOT participate in it, which it still seems to do.

    The queue connection factory is set up to NOT use XA, and thus I expect it to not participate with them either.

    The env:
    was 6.1
    spring 2.0.7


    Spring logging:


    05/11 16:49:59,124 [WebContainer : 0] DEBUG org.springframework.transaction.jta.JtaTransaction Manager - Triggering beforeCompletion synchronization
    05/11 16:49:59,124 [WebContainer : 0] DEBUG org.springframework.transaction.support.Transactio nSynchronizationManager - Removed value [org.springframework.orm.hibernate3.SessionHolder@7 7307730] for key [org.hibernate.impl.SessionFactoryImpl@2fca2fca] from thread [WebContainer : 0]
    05/11 16:49:59,124 [WebContainer : 0] DEBUG org.springframework.transaction.support.Transactio nSynchronizationManager - Removed value [org.springframework.jms.connection.JmsResourceHold er@174a174a] for key [com.ibm.ejs.jms.JMSQueueConnectionFactoryHandle@34 1e341e
    managed connection factory = com.ibm.ejs.jms.WSJMSManagedQueueConnectionFactory @7af87af8
    connection manager = com.ibm.ejs.j2c.ConnectionManager@6cbc6cbc
    restricted methods enabled = false] from thread [WebContainer : 0]
    05/11 16:49:59,140 [WebContainer : 0] DEBUG org.springframework.transaction.jta.JtaTransaction Manager - Initiating transaction rollback

  • #2
    A JmsTransactionManager can help

    Hi!

    Maybe this can help:

    Just use the JmsTransactionManager (for your connection, if not already configured) and TX-annotations or an tx:advice if TX-annotations are already bound to the database TX-manager:

    Code:
        <bean id="jmsTransactionManager"
              class="org.springframework.jms.connection.JmsTransactionManager">
            <property name="connectionFactory" ref="connectionFactory"/>
        </bean>
    
        <tx:annotation-driven transaction-manager="jmsTransactionManager"/>
    
        or
    
        <aop:config>
            <aop:pointcut id="entryPointMethod" expression="execution(* *. senderMethod*(..))"/>
            <aop:advisor
                 advice-ref="jmsTxAdvice"
                 pointcut-ref="entryPointMethod"/>
        </aop:config>
        <tx:advice id="jmsTxAdvice" transaction-manager="jmsTransactionManager">
            <tx:attributes>
                <tx:method name="*" propagation="NOT_SUPPORTED"/>
            </tx:attributes>
        </tx:advice>
    Send your message within an injected bean and if using the annotation style just annotate these sender methods:

    Code:
        @Transactional(propagation = Propagation.NOT_SUPPORTED)
        public ... send(...) {
            ...
    Hope this helps.

    Bye, Torsten

    Comment

    Working...
    X