container-managed transacation; problem with rollback
Hi,
i'd like to be advised in following problem:
I am using Session bean with container-managed transacation to publish message to topic trougth JMS.
Transaction's attribute is Required.
Topic is created in ORACLE DB using ORACLE Advanced Queueing technology. Session bean is deployed to OC4J container.
My problem is following scenario:
- message is published : topicPublisher.publish(topic ,message);
- topic connection is closed: topicConnection.close();
- exception is thrown after enqueue method has been finished in the other method that is in the same transaction as enqueue method
- transaction is marked as Rollbacked (is done by container)
- message gets to (is enqueued into) and remains in topic even though transaction has been marked as rollbacked
Source code:
...
private SessionContext context = null;
...
public void enqueue(String msg){
TopicConnectionFactory topicCF = null;
Topic topic = null;
TopicConnection topicConnection = null;
TopicSession topicSession = null;
TopicPublisher topicPublisher = null;
Message message = null;
try {
if (jndiContext == null){
jndiContext = new InitialContext();
}
//topic connection factory
topicCF = (TopicConnectionFactory)jndiContext.lookup (java:comp/resource/aq_test/TopicConnectionFactories/QUEUE_NAME);
// topic
topic = (Topic)jndiContext.lookup(java:comp/resource/aq_test/Topics/QUEUE_NAME);
topicConnection = topicCF.createTopicConnection();
topicConnection.start();
// according advice in JMS 1.1 tuttorial
topicSession = topicConnection.createTopicSession( treu, 0);
topicPublisher = topicSession.createPublisher(topic);
message = topicSession.createTextMessage(msg);
topicPublisher.publish(topic ,msg);
} catch(NamingException ex) {
System.err.println("topic or factory for topic's connection wasn't found in IniatialContext");
ex.printStackTrace();
context.setRollbackOnly();
} catch (JMSException ex) {
System.err.println("error while enqueueing topic");
ex.printStackTrace();
context.setRollbackOnly();
} finally {
try {
// Closing resources
topicPublisher.close();
topicSession.close();
topicConnection.close();
} catch (JMSException ex) {
System.out.println("error by enqueueing topic while closing topic errors");
ex.printStackTrace();
context.setRollbackOnly();
}
}
}
Thank you very much for any suggestions and hints.
lubbis

