Announcement Announcement Module
No announcement yet.
JMS and DB transactions together..... Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • JMS and DB transactions together.....


    I was keen to understand if the @Transactional annotation would work for JMS as well normal JDBC transaction.

    Like for example I have a method sendJMSMessage which posts a JMS message to a queue while the other method saveToDatabase used JDBC Template to persist some data to database. Then would the @Transactional annotation defined for each method hold good for both?

    OR is it that we have to define the transaction managers separately for each and use AOP?

    I would be much obliged if some one could provide an insight.

    Thanks & Regards,
    Nikhil S K

  • #2
    If the underlying transaction manager is XA (distributed) transaction manager than yes, otherwise its two different transactional resources.
    Id read more here
    and here


    • #3
      It's true that, as Oleg mentioned, in a non-XA configuration you would have 2 different transactional resources. That said, what you mean by the transactional annotation being able to "hold good for both" methods is not always that cut-and-dry. In addition to the links provided by Oleg, I would highly recommend reading this article:

      Basically there are ways to handle "distributed" (or roughly "nested") transactions with and without XA.


      • #4
        Hi Mark and Oleg,

        Thanks for the replies....

        What I meant is that the JMS and JDBC methods / queries are sitting in different DAO's. However both will need to be associated with transactions. But the @Transactional annotation on the methods do not indicate which transaction implementation to use i.e. DatasourceTransaction or JMSTransaction. In this case I was wondering if there is any configuration which will help tell the @Transactional annotation about the underlying transaction manager.

        Thanks & Regards,
        Nikhil S K


        • #5
          Spring now supports a qualifier for the transaction manager within the @Transactional annotation.

          However, be sure to read the docs and article to understand how a transactional JMS session can be scoped along with a DB transaction.


          • #6
            But do you have a requirement to use the same transaction to perform both the operations, the one on the database and one on the queue? Or, you want to use transactional annotation in both the classes which performs operations using different transaction managers independent of each other.
            Your first post gave me an impression that you want both operations to be in one transaction but the the second post conveys something else.


            • #7
              Thanks Mark and Amol,

              @Amol, sorry if the message conveyed seemed like that. But it is not that I want both the operations are in single transaction. The JMS interaction is independent of the JDBC operations. I just was asking if we can use the same underlying transaction manager to handle both kinds of operations (i.e. operation on Queue as well as the Datasource) using the @Transactional annotation.

              Thanks & Regards,