1 Reply Latest reply on Jun 18, 2013 3:16 AM by Michael Owen

    A question about the transaction?

    Michael Owen Newbie

      I created an MDB in my project.As follows:

       

      /**

      * Message-Driven Bean implementation class for: QueueListenerMDB

      */

      @MessageDriven(activationConfig = {

                          @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),

                          @ActivationConfigProperty(propertyName = "destination", propertyValue = "queue/test") })

      @Interceptors(SpringBeanAutowiringInterceptor.class)

      public class QueueListenerMDB implements MessageListener {

                /**

                 * Default constructor.

                 */

                public QueueListenerMDB() {

                }

       

       

                /**

                 * @see MessageListener#onMessage(Message)

                 */

                public void onMessage(Message message) {

                          sendMessage(message);

                }

       

       

                public void sendMessage(Message message) {

                          try {

                                    if (message instanceof TextMessage) {

                                              System.out.println("Queue: I received a TextMessage at "

                                                                  + new Date());

                                              TextMessage msg = (TextMessage) message;

                                              System.out.println("Message is : " + msg.getText());

                                    } else if (message instanceof ObjectMessage) {

                                              System.out.println("Queue: I received an ObjectMessage at "

                                                                  + new Date());

                                              ObjectMessage msg = (ObjectMessage) message;

                                              DBTrigger trigger = (DBTrigger) msg.getObject();

       

                                              triggerService.saveTrigger(trigger);

       

                                              System.out.println("trigger Details: ");

                                              System.out.println(trigger);

                                    } else {

                                              System.out.println("Not valid message for this Queue MDB");

                                    }

                          } catch (JMSException e) {

                                    e.printStackTrace();

                          }

                }

        • 1. Re: A question about the transaction?
          Michael Owen Newbie

          triggerService there is a spring container management, I passed the @ Interceptors (SpringBeanAutowiringInterceptor.class) injected into the MDB that intercaptor,As follows:

          public interface TriggerService {

            void saveTrigger(DBTrigger trigger);

          }

           

          @Service("triggerService")

          public class TriggerServiceImpl implements TriggerService {

            @Autowired

            private TriggerDao triggerDao;

           

            @Override

            public void saveTrigger(DBTrigger trigger) {

            triggerDao.addJobDetail(trigger.getJobDetail());

            triggerDao.addTrigger(trigger.getCronTrigger());

            }

          }

           

          There is about a two-stage transaction when triggerDao.addTrigger (trigger.getCronTrigger ()) This method call fails, why triggerDao.addJobDetail (trigger.getJobDetail ()) This method of data stored in the database Why did not rollback?

           

          I began to think ejb container manages the transaction, but the fact is not my imagination, but then I used org.springframework.transaction.jta.JtaTransactionManager change class to manage, but still no rollback? As follows:

            <context:component-scan base-package="com.pti.aluo.test.*" />

           

            <bean id="transactionManager"

            class="org.springframework.transaction.jta.JtaTransactionManager">

            </bean>

           

            <tx:annotation-driven transaction-manager="transactionManager" />

           

            <aop:config>

            <aop:advisor

            pointcut="execution(public * com.pti.aluo.test.quartz.service.*.*(..))"

            advice-ref="txAdvice" />

            </aop:config>

            <tx:advice id="txAdvice" transaction-manager="transactionManager">

            <tx:attributes>

            <tx:method name="get*" read-only="true" propagation="REQUIRED" />

            <tx:method name="find*" read-only="true" propagation="REQUIRED" />

            <tx:method name="save*" propagation="REQUIRED" />

            <tx:method name="update*" propagation="REQUIRED" />

            <tx:method name="remove*" propagation="REQUIRED" />

            <tx:method name="add*" propagation="REQUIRED" />

            <tx:method name="*" />

            </tx:attributes>

            </tx:advice>