title: Writing messages with Spring JmsTemplate using a TransactionManager
body: <p>Using Spring-JMS it is possible to receive messages within an external transaction context via the <a href="http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/jms/listener/DefaultMessageListenerContainer.html" rel="nofollow">DefaultMessageListenerContainer</a>. </p>
  
  <p>However the only documented way to <em>write</em> a message is via <code>JmsTemplate.send(…)</code> and I can't see how this can be coerced to use a given <code>TransactionManager</code>.</p>
  
  <p>Can anyone point me in the right direction?</p>
  
  <hr>
  
  <p>More info: Ensuring a transaction manager is available (<code>WebSphereUowTransactionManager</code>), using <code>JmsTemplate.write</code> against an Oracle <code>AQjmsFactory.getQueueConnectionFactory(dataSource)</code> results in:</p>
  
  <pre><code>org.springframework.jms.UncategorizedJmsException: Uncategorized exception occured during JMS processing; nested exception is oracle.jms.AQjmsException: could not use local transaction commit in a global transaction
    at org.springframework.jms.support.JmsUtils.convertJmsAccessException(JmsUtils.java:316)
    at org.springframework.jms.support.JmsAccessor.convertJmsAccessException(JmsAccessor.java:168)
    at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:469)
    at org.springframework.jms.core.JmsTemplate.send(JmsTemplate.java:534)
  Caused by: oracle.jms.AQjmsException: could not use local transaction commit in a global transaction
    at oracle.jms.AQjmsSession.commitNoCheck(AQjmsSession.java:1053)
    at oracle.jms.AQjmsSession.commit(AQjmsSession.java:1021)
    at org.springframework.jms.support.JmsUtils.commitIfNecessary(JmsUtils.java:217)
    at org.springframework.jms.core.JmsTemplate.doSend(JmsTemplate.java:573)
    at org.springframework.jms.core.JmsTemplate$3.doInJms(JmsTemplate.java:536)
    at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:466)
    ... 24 more
  Caused by: java.sql.SQLException: could not use local transaction commit in a global transaction
    at oracle.jdbc.driver.PhysicalConnection.disallowGlobalTxnMode(PhysicalConnection.java:6647)
    at oracle.jdbc.driver.PhysicalConnection.commit(PhysicalConnection.java:3635)
    at oracle.jdbc.driver.PhysicalConnection.commit(PhysicalConnection.java:3680)
    at oracle.jdbc.OracleConnectionWrapper.commit(OracleConnectionWrapper.java:133)
    at oracle.jms.AQjmsSession.commitNoCheck(AQjmsSession.java:1049)
    ... 29 more
  </code></pre>
  
  <p>So whilst I have no reason to doubt the advise below, I am not able to test it as I can't figure out how to get AQ JMS to not attempt a commit. Will update as I learn more.</p>