3 Replies Latest reply on May 6, 2011 1:38 PM by ryanhos

    JMS Rollback and Oracle Database.

    henrique.malheiro

      Hi,

       

      I need some monitoring on my pipelines so I developed a custom action that writes to an Oracle Database information about the state of the processing.

       

      Whenever a RuntimeException causes a rollback and a redeliver of the message to the JMS Queue (transacted=true), the information stored in the Oracle database about the error by the monitor action also rollsback.

       

      Is there any way to make the database operations performed by the monitor action persist despite the JMS transaction rollbacks?

       

      Thanks,

      Henrique Malheiro

        • 1. JMS Rollback and Oracle Database.
          h.wolffenbuttel

          You could register a new datasource to get a new connection to handle your transaction. Something like:

           

           

           

          public static Connection getConnection() throws SQLException {

              Context c = null;

              if (jdbcFactory == null) {

                try {

                  c = new InitialContext();

                  jdbcFactory = (DataSource) c.lookup("java:jdbc/YourConnectionDS");

                }

                catch (NamingException e) {

                  throw new SQLException(e.getMessage());

                }

              }

              return jdbcFactory.getConnection();

            }

           

           

           

           

           

           

           

           

           

           

           

           

           

           

           

           

          Regards,

           

          Hans

          • 2. JMS Rollback and Oracle Database.
            henrique.malheiro

            Hi,

             

            Thanks for your reply.

             

            I have the action monitor implemented exactly as you suggested, with a new datasource. Neverthless, the database operations performed by the monitor action don't persist upon JMS rollbacks, which I don't understand why. How are the two related?

             

            Best regards,

            Henrique Malheiro

            • 3. Re: JMS Rollback and Oracle Database.
              ryanhos

              I suspect that your new datasource is a local-tx or xa datasource.  The new datasource should be a no-tx datasource.  This page explains how to configure datasources.  A local or XA datasource will provide connections that participate in an enclosing transaction, whereas a no-tx datasource does not utilize any of the container-provided transaction demarcation logic.  It's often a good idea to have a single no-tx datasource available for performing operations like audit logging and other system-related tasks that should not fail a business transaction if the system task fails to execute.

               

              In the event that you in fact do have a no-tx datasource configured, I'd ask you to examine your code to make sure you're actually committing the transaction and closing the connection.

               

              I hope this has been helpful.  If you need additional assistance configuring and consuming datasources, I ask that you seek help on the JCA message board, as the topics you're likely to ask about are not specifically ESB related.