title: Spring JMS Oracle AQ Too many transactions
body: <p>I have created a basic Spring applicatin to read from Oracle AQ. I am experiencing following issues. Kindly help me on this</p>
  
  <p>1)- Messages placed on the queue (by PL/SQL code) prior to starting of my spring application are not dequeued by it.
  2)- A message that is successfull read from the queue should be removed from the queue. This is not happening. All messages remain in Queue Table.
  3)- Once a message is read, the process goes in block/waiting state, as shown by the log below, if any message is place on queue during that period, that message is ignored. It is taking 30 - 40 secs to commit the transaction</p>
  
  <pre><code>2012-02-08 13:26:37,700 DEBUG [org.springframework.data.jdbc.jms.listener.oracle.AdtMessageListenerContainer] - &lt;Received message of type [class oracle.jms.AQjmsAdtMessage] from consumer [oracle.jms.AQjmsConsumer@1989b5] of transactional session [oracle.jms.AQjmsSession@189c036]&gt;
  2012-02-08 13:26:37,700 DEBUG [org.springframework.data.jdbc.support.oracle.BeanPropertyStructMapper] - &lt;Mapping column 'id' to property 'id' of type class java.math.BigDecimal&gt;
  2012-02-08 13:26:37,700 DEBUG [org.springframework.data.jdbc.support.oracle.BeanPropertyStructMapper] - &lt;Mapping column 'type_cd' to property 'type_cd' of type class java.lang.String&gt;
  2012-02-08 13:26:37,700 INFO [com.test.oracle.aq.ProductDelegate] - &lt;Product [id=6, type_cd=Test Product Code]&gt;
  2012-02-08 13:26:37,715 DEBUG [org.springframework.jdbc.core.JdbcTemplate] - &lt;Executing SQL update [INSERT INTO Product(id, type_cd) values(6, 'Test Product Code')]&gt;
  2012-02-08 13:26:37,731 DEBUG [org.springframework.jdbc.core.JdbcTemplate] - &lt;SQL update affected 1 rows&gt;
  2012-02-08 13:26:57,295 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - &lt;Initiating transaction commit&gt;
  2012-02-08 13:26:57,295 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - &lt;Committing JDBC transaction on Connection [oracle.jdbc.driver.T4CConnection@1860038]&gt;
  2012-02-08 13:26:57,295 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - &lt;Releasing JDBC Connection [oracle.jdbc.driver.T4CConnection@1860038] after transaction&gt;
  2012-02-08 13:26:57,295 DEBUG [org.springframework.jdbc.datasource.DataSourceUtils] - &lt;Returning JDBC Connection to DataSource&gt;
  </code></pre>
  
  <p>4)- Why it is making soo many tansactions? While waiting on queue</p>
  
  <pre><code>2012-02-08 13:22:58,937 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - &lt;Creating new transaction with name [org.springframework.data.jdbc.jms.listener.oracle.AdtMessageListenerContainer#0]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT&gt;
  2012-02-08 13:22:59,000 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - &lt;Acquired Connection [oracle.jdbc.driver.T4CConnection@9b688e] for JDBC transaction&gt;
  2012-02-08 13:22:59,000 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - &lt;Switching JDBC Connection [oracle.jdbc.driver.T4CConnection@9b688e] to manual commit&gt;
  2012-02-08 13:23:00,045 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - &lt;Initiating transaction commit&gt;
  2012-02-08 13:23:00,045 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - &lt;Committing JDBC transaction on Connection [oracle.jdbc.driver.T4CConnection@9b688e]&gt;
  2012-02-08 13:23:00,061 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - &lt;Releasing JDBC Connection [oracle.jdbc.driver.T4CConnection@9b688e] after transaction&gt;
  2012-02-08 13:23:00,061 DEBUG [org.springframework.jdbc.datasource.DataSourceUtils] - &lt;Returning JDBC Connection to DataSource&gt;
  2012-02-08 13:23:00,061 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - &lt;Creating new transaction with name [org.springframework.data.jdbc.jms.listener.oracle.AdtMessageListenerContainer#0]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT&gt;
  2012-02-08 13:23:00,093 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - &lt;Acquired Connection [oracle.jdbc.driver.T4CConnection@eca36e] for JDBC transaction&gt;
  2012-02-08 13:23:00,093 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - &lt;Switching JDBC Connection [oracle.jdbc.driver.T4CConnection@eca36e] to manual commit&gt;
  2012-02-08 13:23:01,154 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - &lt;Initiating transaction commit&gt;
  2012-02-08 13:23:01,154 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - &lt;Committing JDBC transaction on Connection [oracle.jdbc.driver.T4CConnection@eca36e]&gt;
  2012-02-08 13:23:01,155 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - &lt;Releasing JDBC Connection [oracle.jdbc.driver.T4CConnection@eca36e] after transaction&gt;
  2012-02-08 13:23:01,155 DEBUG [org.springframework.jdbc.datasource.DataSourceUtils] - &lt;Returning JDBC Connection to DataSource&gt;
  2012-02-08 13:23:01,155 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - &lt;Creating new transaction with name [org.springframework.data.jdbc.jms.listener.oracle.AdtMessageListenerContainer#0]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT&gt;
  2012-02-08 13:23:01,202 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - &lt;Acquired Connection [oracle.jdbc.driver.T4CConnection@19b4748] for JDBC transaction&gt;
  2012-02-08 13:23:01,202 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - &lt;Switching JDBC Connection [oracle.jdbc.driver.T4CConnection@19b4748] to manual commit&gt;
  2012-02-08 13:23:02,263 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - &lt;Initiating transaction commit&gt;
  2012-02-08 13:23:02,263 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - &lt;Committing JDBC transaction on Connection [oracle.jdbc.driver.T4CConnection@19b4748]&gt;
  2012-02-08 13:23:02,278 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - &lt;Releasing JDBC Connection [oracle.jdbc.driver.T4CConnection@19b4748] after transaction&gt;
  2012-02-08 13:23:02,278 DEBUG [org.springframework.jdbc.datasource.DataSourceUtils] - &lt;Returning JDBC Connection to DataSource&gt;
  2012-02-08 13:23:02,278 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - &lt;Creating new transaction with name [org.springframework.data.jdbc.jms.listener.oracle.AdtMessageListenerContainer#0]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT&gt;
  2012-02-08 13:23:02,311 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - &lt;Acquired Connection [oracle.jdbc.driver.T4CConnection@1a41cc7] for JDBC transaction&gt;
  </code></pre>
  
  <p>Below are my spring config</p>
  
  <pre><code>&lt;bean id="dataSource" class="oracle.jdbc.pool.OracleConnectionPoolDataSource"&gt;
      &lt;property name="URL" value="jdbc:oracle:thin:@//localhost:1521/XE" /&gt;
      &lt;property name="user" value="migration" /&gt;
      &lt;property name="password" value="password" /&gt;
  &lt;/bean&gt;
  &lt;bean id="transactionManager"
      class="org.springframework.jdbc.datasource.DataSourceTransactionManager"
      lazy-init="true"&gt;
      &lt;property name="dataSource" ref="dataSource" /&gt;
  &lt;/bean&gt;
  &lt;bean id="messageDelegate" class="com.test.oracle.aq.ProductDelegate" /&gt;
  &lt;jms:listener-container connection-factory="connectionFactory"   
      transaction-manager="transactionManager"
      message-converter="messageConverter" 
      container-class="org.springframework.data.jdbc.jms.listener.oracle.AdtMessageListenerContainer" destination-type="topic"&gt;
      &lt;jms:listener destination="MIGRATION.PRODUCT_QUEUE" ref="messageDelegate" method="handleMessage" /&gt;
  &lt;/jms:listener-container&gt;
  &lt;bean id="messageConverter"                                                          
          class="org.springframework.data.jdbc.jms.support.converter.oracle.MappingAdtMessageConverter"&gt;
      &lt;constructor-arg&gt;
          &lt;bean class="org.springframework.data.jdbc.jms.support.oracle.StructDatumMapper"&gt;
              &lt;constructor-arg index="0" value="MIGRATION.PRODUCT_T"/&gt;
              &lt;constructor-arg index="1" value="com.test.oracle.aq.Product"/&gt;
          &lt;/bean&gt;
      &lt;/constructor-arg&gt;
  &lt;/bean&gt;
  &lt;orcl:aq-jms-connection-factory id="connectionFactory" data-source="dataSource"/&gt; 
  &lt;bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate"&gt;
      &lt;property name="connectionFactory" ref="connectionFactory" /&gt;
      &lt;property name="sessionTransacted" value="true"/&gt;
  &lt;/bean&gt;
  </code></pre>