shaby775
Oct 13th, 2004, 10:04 AM
Hi,
I am using Spring 1.1.1 and hibernate 2.1.6 with Oracle 9i and JBOss 3.2.3. We need to use JtaTransactionManager as we need both jms and hiberanate calls in same method. I setup an xa capable datasource in JBoss and it is working fine and i am getting the connection factory from java:/JmsXA location as from Jboss docs i get to know that it is how it is setup. Now if i use only hibernate it works fine with xa datasourec and jta transaction manager without any problem (using oracle xa datasource and setting pad to true). But when i enable the jms usage (by using jmsTemplate and xa aware donnectioFactory) it gave error as it tries to commit locally and i get the exception TransactionInProgress. I dont know why it is happening all my resources are xa aware and coming from app server jndi.... It should be managed properly by JtaTransactiion manager. Why dont i ma getting distributed transaction and why not spring idetects that their is ongoing jta transaction and it should participate in it. Why?????. Why does it tries to commit it locally ......it is the duty of jta transaction manager to commit not of session. Is it some bug that JmsTemplate102 not detect ongoing xa transaction or is there any error in my configuration. Please help me asap
My code is as follows
// JmsTopicSender.java
package com.sequelsys.server.scheduling.jms;
import javax.jms.*;
import org.springframework.jms.core.*;
public class JmsTopicSender {
private JmsTemplate102 jt;
private ConnectionFactory connectionFactory;
private Topic topic;
public void simpleSend() {
jt = new JmsTemplate102(connectionFactory, true);
jt.send(topic, new MessageCreator() {
public Message createMessage(Session session) throws JMSException {
return session.createTextMessage("Record inserted succefully");
}
});
}
public void setConnectionFactory(ConnectionFactory cf) {
connectionFactory = cf;
}
public void setTopic(Topic q) {
topic = q;
}
}
This class is used from foloowing class which first use Hibernate to save the domain object
package com.sequelsys.server.scheduling.service;
import org.springframework.dao.*;
import com.sequelsys.common.businessservice.scheduling.*;
import com.sequelsys.common.model.scheduling.*;
import com.sequelsys.server.scheduling.dao.*;
import com.sequelsys.server.scheduling.jms.JmsTopicSender ;
public class HolidayScheduleService
implements IHolidayScheduleService {
private IHolidayScheduleDAO holidayScheduleDAO;
private JmsTopicSender jmsTopicSender;
public void setHolidayScheduleDAO(IHolidayScheduleDAO holidayScheduleDAO) {
this.holidayScheduleDAO = holidayScheduleDAO;
}
public void setJmsTopicSender(JmsTopicSender jmsTopicSender) {
this.jmsTopicSender = jmsTopicSender;
}
public IHolidayScheduleDAO getHolidayScheduleDAO() {
return holidayScheduleDAO;
}
public JmsTopicSender getJmsTopicSender() {
return jmsTopicSender;
}
public HolidayScheduleService() {
}
public HolidaysScheduleModel createHolidaySchedule(HolidayScheduleBusinessServi ce holidayScheduleBusinessService) throws DataAccessException
{
HolidaysScheduleModel holidaysScheduleModel = this.holidayScheduleDAO.create(holidayScheduleBusi nessService.getHolidaysScheduleModel());
//HolidaysScheduleModel holidaysScheduleModel = new HolidaysScheduleModel();
this.jmsTopicSender.simpleSend();
return holidaysScheduleModel;
}
}
The application context file is as follows
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<!--
- Application context definition for Petclinic on Hibernate.
-->
<beans>
<!-- ========================= RESOURCE DEFINITIONS ========================= -->
<bean id="messageSource" class="org.springframework.context.support.ResourceBundle MessageSource">
<property name="basename">
<value>messages</value>
</property>
</bean>
<!-- JNDI DataSource for J2EE environments -->
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName"><value>java:/XAOracleDS</value></property>
</bean>
<!-- Hibernate SessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSessionFact oryBean">
<property name="dataSource"><ref local="dataSource"/></property>
<property name="mappingResources">
<value>com/sequelsys/common/model/scheduling/HolidaysSchedule.hbm.xml</value>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">net.sf.hibernate.dialect.Oracle9Dialect</prop>
<prop key="hibernate.show_sql">true</prop>
<!-- These lines are only required if we r using Jta transaction manager. They ensure jvm level caching and appropriate callbacks for jvm-->
<!--
<prop key="hibernate.transaction.manager_lookup_class">net.sf.hibernate.transaction.JBossTransactionManag erLookup</prop>
<prop key="hibernate.jta.UserTransaction">java:comp/UserTransaction</prop> -->
</props>
</property>
</bean>
<!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA) -->
<!--
<bean id="transactionManager" class="org.springframework.orm.hibernate.HibernateTransac tionManager">
<property name="sessionFactory"><ref local="sessionFactory"/></property>
</bean>
-->
<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransaction Manager">
<property name="transactionManagerName"><value>java:/TransactionManager</value></property>
</bean>
<bean id="holidayScheduleDAO" class="com.sequelsys.server.scheduling.dao.HolidaySchedul eDAO">
<property name="sessionFactory"><ref local="sessionFactory"/></property>
</bean>
<bean id="connectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName"><value>jms/connectionFactory</value></property>
<property name="resourceRef"><value>true</value></property>
</bean>
<bean id="destination" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName"><value>jms/topic</value></property>
<property name="resourceRef"><value>true</value></property>
</bean>
<bean id="jmsTopicSender" class="com.sequelsys.server.scheduling.jms.JmsTopicSender">
<property name="connectionFactory"><ref local="connectionFactory"/></property>
<property name="topic"><ref local="destination"/></property>
</bean>
<!-- ========================= BUSINESS OBJECT DEFINITIONS ========================= -->
<!--
- A parent bean definition which is a base definition for transaction proxies.
- It is markes as abstract, since it is never supposed to be instantiated itself.
- We set shared transaction attributes here, following our naming patterns.
- The attributes can still be overridden in child bean definitions.
-->
<bean id="baseTransactionProxy" class="org.springframework.transaction.interceptor.Transa ctionProxyFactoryBean" abstract="true">
<property name="transactionManager"><ref bean="transactionManager"/></property>
<property name="transactionAttributes">
<props>
<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="load*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="create*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<bean id="holidayScheduleService" parent="baseTransactionProxy">
<property name="target">
<bean class="com.sequelsys.server.scheduling.service.HolidaySch eduleService">
<property name="holidayScheduleDAO"><ref local="holidayScheduleDAO"/></property>
<property name="jmsTopicSender"><ref local="jmsTopicSender"/></property>
</bean>
</property>
</bean>
<bean id="schedulingFacade" class="com.sequelsys.server.common.service.SchedulingFaca de">
<property name="messageSource"><ref local="messageSource"/></property>
<property name="holidayScheduleService"><ref local="holidayScheduleService"/></property>
</bean>
</beans>
and web.xml is
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC '-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN' 'http://java.sun.com/dtd/web-app_2_3.dtd'>
<!--
- $Id: web.xml,v 1.1 2004/08/01 23:03:20 benalex Exp $
-->
<web-app>
<display-name>SampleProject</display-name>
<description>
Provides an example for using Spring framework
</description>
<!--
- Location of the XML file that defines the root application context
- Applied by ContextLoaderListener.
-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext-hibernate.xml</param-value>
</context-param>
<!--
- Loads the root application context of this web app at startup,
- by default from "/WEB-INF/applicationContext.xml".
- Use WebApplicationContextUtils.getWebApplicationContex t(servletContext)
- to access it anywhere in the web application, outside of the framework.
-->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListe ner</listener-class>
</listener>
<servlet>
<servlet-name>ws</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<!--
- Dispatcher servlet mapping for HTTP web services.
- (see ws-servlet.xml for the controllers).
-->
<servlet-mapping>
<servlet-name>ws</servlet-name>
<url-pattern>/ws/*</url-pattern>
</servlet-mapping>
<resource-env-ref>
<resource-env-ref-name>jms/topic</resource-env-ref-name>
<resource-env-ref-type>javax.jms.Topic</resource-env-ref-type>
</resource-env-ref>
<resource-ref>
<description>JMS Connection Factory</description>
<res-ref-name>jms/connectionFactory</res-ref-name>
<res-type>javax.jms.TopicConnectionFactory</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
</web-app>
jboss.xml is as
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jboss-web PUBLIC "-//JBoss//DTD Web Application 2.3V2//EN" "http://www.jboss.org/j2ee/dtd/jboss-web_3_2.dtd">
<jboss-web>
<context-root>SampleProjectModule</context-root>
<resource-env-ref>
<resource-env-ref-name>jms/topic</resource-env-ref-name>
<jndi-name>topic/EMRTopic</jndi-name>
</resource-env-ref>
<resource-ref>
<res-ref-name>jms/connectionFactory</res-ref-name>
<res-type>javax.jms.TopicConnectionFactory</res-type>
<jndi-name>java:/JmsXA</jndi-name>
<res-auth>Container</res-auth>
</resource-ref>
</jboss-web>
thouh not as relevant the DAO is as
package com.sequelsys.server.scheduling.dao;
import org.springframework.dao.*;
import org.springframework.orm.hibernate.support.*;
import com.sequelsys.common.model.scheduling.*;
public class HolidayScheduleDAO extends HibernateDaoSupport
implements IHolidayScheduleDAO {
public HolidayScheduleDAO() {
}
public HolidaysScheduleModel create(HolidaysScheduleModel holidaysScheduleModel) throws DataAccessException
{
Long seqNo = (Long) this.getHibernateTemplate().save(holidaysScheduleM odel);
holidaysScheduleModel.setSeqNum(seqNo);
return holidaysScheduleModel;
}
}
I am getting the following exception
19:07:16,021 ERROR [STDERR] org.springframework.jms.TransactionInProgressExcep tion: Should not be call from a XASession; nested exception is javax.jms.TransactionInProgressException: Should not be call from a XASession; nested exception is javax.jms.TransactionInProgressException: Should not be call from a XASession
19:07:16,021 ERROR [STDERR] javax.jms.TransactionInProgressException: Should not be call from a XASession
19:07:16,021 ERROR [STDERR] at org.jboss.mq.SpySession.commit(SpySession.java:410 )
19:07:16,021 ERROR [STDERR] at org.jboss.resource.adapter.jms.JmsSession.commit(J msSession.java:166)
19:07:16,068 ERROR [STDERR] at org.springframework.jms.core.JmsTemplate.doSend(Jm sTemplate.java:609)
19:07:16,068 ERROR [STDERR] at org.springframework.jms.core.JmsTemplate$2.doInJms (JmsTemplate.java:583)
19:07:16,068 ERROR [STDERR] at org.springframework.jms.core.JmsTemplate.execute(J msTemplate.java:548)
19:07:16,068 ERROR [STDERR] at org.springframework.jms.core.JmsTemplate.execute(J msTemplate.java:560)
19:07:16,068 ERROR [STDERR] at org.springframework.jms.core.JmsTemplate.send(JmsT emplate.java:581)
19:07:16,084 ERROR [STDERR] at com.sequelsys.server.scheduling.jms.JmsTopicSender .simpleSend(JmsTopicSender.java:13)
19:07:16,084 ERROR [STDERR] at com.sequelsys.server.scheduling.service.HolidaySch eduleService.createHolidaySchedule(HolidaySchedule Service.java:37)
19:07:16,084 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
19:07:16,084 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
19:07:16,084 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
19:07:16,084 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:324)
19:07:16,084 ERROR [STDERR] at org.springframework.aop.framework.AopProxyUtils.in vokeJoinpointUsingReflection(AopProxyUtils.java:61 )
19:07:16,084 ERROR [STDERR] at org.springframework.aop.framework.ReflectiveMethod Invocation.invokeJoinpoint(ReflectiveMethodInvocat ion.java:149)
19:07:16,084 ERROR [STDERR] at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :116)
19:07:16,084 ERROR [STDERR] at org.springframework.transaction.interceptor.Transa ctionInterceptor.invoke(TransactionInterceptor.jav a:56)
19:07:16,099 ERROR [STDERR] at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :138)
19:07:16,099 ERROR [STDERR] at org.springframework.aop.framework.JdkDynamicAopPro xy.invoke(JdkDynamicAopProxy.java:152)
19:07:16,099 ERROR [STDERR] at $Proxy30.createHolidaySchedule(Unknown Source)
19:07:16,099 ERROR [STDERR] at com.sequelsys.server.common.service.SchedulingFaca de.createHolidaySchedule(SchedulingFacade.java:37)
19:07:16,099 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
19:07:16,099 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
19:07:16,099 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
19:07:16,099 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:324)
19:07:16,099 ERROR [STDERR] at org.springframework.aop.framework.AopProxyUtils.in vokeJoinpointUsingReflection(AopProxyUtils.java:61 )
19:07:16,099 ERROR [STDERR] at org.springframework.aop.framework.JdkDynamicAopPro xy.invoke(JdkDynamicAopProxy.java:142)
19:07:16,099 ERROR [STDERR] at $Proxy30.createHolidaySchedule(Unknown Source)
19:07:16,099 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
19:07:16,099 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
19:07:16,099 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
19:07:16,099 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:324)
19:07:16,099 ERROR [STDERR] at org.springframework.remoting.support.RemoteInvocat ion.invoke(RemoteInvocation.java:179)
19:07:16,115 ERROR [STDERR] at org.springframework.remoting.support.DefaultRemote InvocationExecutor.invoke(DefaultRemoteInvocationE xecutor.java:32)
19:07:16,115 ERROR [STDERR] at org.springframework.remoting.support.RemoteInvocat ionBasedExporter.invoke(RemoteInvocationBasedExpor ter.java:70)
19:07:16,115 ERROR [STDERR] at org.springframework.remoting.support.RemoteInvocat ionBasedExporter.invokeAndCreateResult(RemoteInvoc ationBasedExporter.java:106)
19:07:16,115 ERROR [STDERR] at org.springframework.remoting.httpinvoker.HttpInvok erServiceExporter.handleRequest(HttpInvokerService Exporter.java:63)
19:07:16,115 ERROR [STDERR] at org.springframework.web.servlet.mvc.SimpleControll erHandlerAdapter.handle(SimpleControllerHandlerAda pter.java:44)
19:07:16,115 ERROR [STDERR] at org.springframework.web.servlet.DispatcherServlet. doService(DispatcherServlet.java:522)
19:07:16,115 ERROR [STDERR] at org.springframework.web.servlet.FrameworkServlet.s ervice(FrameworkServlet.java:321)
19:07:16,115 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet .java:853)
19:07:16,115 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:247)
19:07:16,115 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:193)
19:07:16,115 ERROR [STDERR] at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:256)
19:07:16,115 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline$Standard PipelineValveContext.invokeNext(StandardPipeline.j ava:643)
19:07:16,115 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:480)
19:07:16,115 ERROR [STDERR] at org.apache.catalina.core.ContainerBase.invoke(Cont ainerBase.java:995)
19:07:16,130 ERROR [STDERR] at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:191)
19:07:16,130 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline$Standard PipelineValveContext.invokeNext(StandardPipeline.j ava:643)
19:07:16,130 ERROR [STDERR] at org.jboss.web.tomcat.security.JBossSecurityMgrReal m.invoke(JBossSecurityMgrRealm.java:220)
19:07:16,130 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline$Standard PipelineValveContext.invokeNext(StandardPipeline.j ava:641)
19:07:16,130 ERROR [STDERR] at org.apache.catalina.valves.CertificatesValve.invok e(CertificatesValve.java:246)
19:07:16,130 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline$Standard PipelineValveContext.invokeNext(StandardPipeline.j ava:641)
19:07:16,130 ERROR [STDERR] at org.jboss.web.tomcat.tc4.statistics.ContainerStats Valve.invoke(ContainerStatsValve.java:76)
19:07:16,130 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline$Standard PipelineValveContext.invokeNext(StandardPipeline.j ava:641)
19:07:16,146 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:480)
19:07:16,146 ERROR [STDERR] at org.apache.catalina.core.ContainerBase.invoke(Cont ainerBase.java:995)
19:07:16,146 ERROR [STDERR] at org.apache.catalina.core.StandardContext.invoke(St andardContext.java:2417)
19:07:16,146 ERROR [STDERR] at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:180)
19:07:16,146 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline$Standard PipelineValveContext.invokeNext(StandardPipeline.j ava:643)
19:07:16,146 ERROR [STDERR] at org.apache.catalina.valves.ErrorDispatcherValve.in voke(ErrorDispatcherValve.java:171)
19:07:16,146 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline$Standard PipelineValveContext.invokeNext(StandardPipeline.j ava:641)
19:07:16,146 ERROR [STDERR] at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:172)
19:07:16,146 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline$Standard PipelineValveContext.invokeNext(StandardPipeline.j ava:641)
19:07:16,146 ERROR [STDERR] at org.jboss.web.tomcat.security.SecurityAssociationV alve.invoke(SecurityAssociationValve.java:65)
19:07:16,146 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline$Standard PipelineValveContext.invokeNext(StandardPipeline.j ava:641)
19:07:16,146 ERROR [STDERR] at org.apache.catalina.valves.AccessLogValve.invoke(A ccessLogValve.java:577)
19:07:16,146 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline$Standard PipelineValveContext.invokeNext(StandardPipeline.j ava:641)
19:07:16,162 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:480)
19:07:16,162 ERROR [STDERR] at org.apache.catalina.core.ContainerBase.invoke(Cont ainerBase.java:995)
19:07:16,162 ERROR [STDERR] at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:174)
19:07:16,162 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline$Standard PipelineValveContext.invokeNext(StandardPipeline.j ava:643)
19:07:16,162 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:480)
19:07:16,162 ERROR [STDERR] at org.apache.catalina.core.ContainerBase.invoke(Cont ainerBase.java:995)
19:07:16,162 ERROR [STDERR] at org.apache.coyote.tomcat4.CoyoteAdapter.service(Co yoteAdapter.java:197)
19:07:16,162 ERROR [STDERR] at org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:781)
19:07:16,162 ERROR [STDERR] at org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.processConnection(Http11Protocol.jav a:549)
19:07:16,162 ERROR [STDERR] at org.apache.tomcat.util.net.TcpWorkerThread.runIt(P oolTcpEndpoint.java:605)
19:07:16,162 ERROR [STDERR] at org.apache.tomcat.util.threads.ThreadPool$ControlR unnable.run(ThreadPool.java:677)
19:07:16,162 ERROR [STDERR] at java.lang.Thread.run(Thread.java:534)
I am quite sure that db part is working fine but jms somehow dont know the transaction. Please do it asap
I am using Spring 1.1.1 and hibernate 2.1.6 with Oracle 9i and JBOss 3.2.3. We need to use JtaTransactionManager as we need both jms and hiberanate calls in same method. I setup an xa capable datasource in JBoss and it is working fine and i am getting the connection factory from java:/JmsXA location as from Jboss docs i get to know that it is how it is setup. Now if i use only hibernate it works fine with xa datasourec and jta transaction manager without any problem (using oracle xa datasource and setting pad to true). But when i enable the jms usage (by using jmsTemplate and xa aware donnectioFactory) it gave error as it tries to commit locally and i get the exception TransactionInProgress. I dont know why it is happening all my resources are xa aware and coming from app server jndi.... It should be managed properly by JtaTransactiion manager. Why dont i ma getting distributed transaction and why not spring idetects that their is ongoing jta transaction and it should participate in it. Why?????. Why does it tries to commit it locally ......it is the duty of jta transaction manager to commit not of session. Is it some bug that JmsTemplate102 not detect ongoing xa transaction or is there any error in my configuration. Please help me asap
My code is as follows
// JmsTopicSender.java
package com.sequelsys.server.scheduling.jms;
import javax.jms.*;
import org.springframework.jms.core.*;
public class JmsTopicSender {
private JmsTemplate102 jt;
private ConnectionFactory connectionFactory;
private Topic topic;
public void simpleSend() {
jt = new JmsTemplate102(connectionFactory, true);
jt.send(topic, new MessageCreator() {
public Message createMessage(Session session) throws JMSException {
return session.createTextMessage("Record inserted succefully");
}
});
}
public void setConnectionFactory(ConnectionFactory cf) {
connectionFactory = cf;
}
public void setTopic(Topic q) {
topic = q;
}
}
This class is used from foloowing class which first use Hibernate to save the domain object
package com.sequelsys.server.scheduling.service;
import org.springframework.dao.*;
import com.sequelsys.common.businessservice.scheduling.*;
import com.sequelsys.common.model.scheduling.*;
import com.sequelsys.server.scheduling.dao.*;
import com.sequelsys.server.scheduling.jms.JmsTopicSender ;
public class HolidayScheduleService
implements IHolidayScheduleService {
private IHolidayScheduleDAO holidayScheduleDAO;
private JmsTopicSender jmsTopicSender;
public void setHolidayScheduleDAO(IHolidayScheduleDAO holidayScheduleDAO) {
this.holidayScheduleDAO = holidayScheduleDAO;
}
public void setJmsTopicSender(JmsTopicSender jmsTopicSender) {
this.jmsTopicSender = jmsTopicSender;
}
public IHolidayScheduleDAO getHolidayScheduleDAO() {
return holidayScheduleDAO;
}
public JmsTopicSender getJmsTopicSender() {
return jmsTopicSender;
}
public HolidayScheduleService() {
}
public HolidaysScheduleModel createHolidaySchedule(HolidayScheduleBusinessServi ce holidayScheduleBusinessService) throws DataAccessException
{
HolidaysScheduleModel holidaysScheduleModel = this.holidayScheduleDAO.create(holidayScheduleBusi nessService.getHolidaysScheduleModel());
//HolidaysScheduleModel holidaysScheduleModel = new HolidaysScheduleModel();
this.jmsTopicSender.simpleSend();
return holidaysScheduleModel;
}
}
The application context file is as follows
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<!--
- Application context definition for Petclinic on Hibernate.
-->
<beans>
<!-- ========================= RESOURCE DEFINITIONS ========================= -->
<bean id="messageSource" class="org.springframework.context.support.ResourceBundle MessageSource">
<property name="basename">
<value>messages</value>
</property>
</bean>
<!-- JNDI DataSource for J2EE environments -->
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName"><value>java:/XAOracleDS</value></property>
</bean>
<!-- Hibernate SessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSessionFact oryBean">
<property name="dataSource"><ref local="dataSource"/></property>
<property name="mappingResources">
<value>com/sequelsys/common/model/scheduling/HolidaysSchedule.hbm.xml</value>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">net.sf.hibernate.dialect.Oracle9Dialect</prop>
<prop key="hibernate.show_sql">true</prop>
<!-- These lines are only required if we r using Jta transaction manager. They ensure jvm level caching and appropriate callbacks for jvm-->
<!--
<prop key="hibernate.transaction.manager_lookup_class">net.sf.hibernate.transaction.JBossTransactionManag erLookup</prop>
<prop key="hibernate.jta.UserTransaction">java:comp/UserTransaction</prop> -->
</props>
</property>
</bean>
<!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA) -->
<!--
<bean id="transactionManager" class="org.springframework.orm.hibernate.HibernateTransac tionManager">
<property name="sessionFactory"><ref local="sessionFactory"/></property>
</bean>
-->
<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransaction Manager">
<property name="transactionManagerName"><value>java:/TransactionManager</value></property>
</bean>
<bean id="holidayScheduleDAO" class="com.sequelsys.server.scheduling.dao.HolidaySchedul eDAO">
<property name="sessionFactory"><ref local="sessionFactory"/></property>
</bean>
<bean id="connectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName"><value>jms/connectionFactory</value></property>
<property name="resourceRef"><value>true</value></property>
</bean>
<bean id="destination" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName"><value>jms/topic</value></property>
<property name="resourceRef"><value>true</value></property>
</bean>
<bean id="jmsTopicSender" class="com.sequelsys.server.scheduling.jms.JmsTopicSender">
<property name="connectionFactory"><ref local="connectionFactory"/></property>
<property name="topic"><ref local="destination"/></property>
</bean>
<!-- ========================= BUSINESS OBJECT DEFINITIONS ========================= -->
<!--
- A parent bean definition which is a base definition for transaction proxies.
- It is markes as abstract, since it is never supposed to be instantiated itself.
- We set shared transaction attributes here, following our naming patterns.
- The attributes can still be overridden in child bean definitions.
-->
<bean id="baseTransactionProxy" class="org.springframework.transaction.interceptor.Transa ctionProxyFactoryBean" abstract="true">
<property name="transactionManager"><ref bean="transactionManager"/></property>
<property name="transactionAttributes">
<props>
<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="load*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="create*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<bean id="holidayScheduleService" parent="baseTransactionProxy">
<property name="target">
<bean class="com.sequelsys.server.scheduling.service.HolidaySch eduleService">
<property name="holidayScheduleDAO"><ref local="holidayScheduleDAO"/></property>
<property name="jmsTopicSender"><ref local="jmsTopicSender"/></property>
</bean>
</property>
</bean>
<bean id="schedulingFacade" class="com.sequelsys.server.common.service.SchedulingFaca de">
<property name="messageSource"><ref local="messageSource"/></property>
<property name="holidayScheduleService"><ref local="holidayScheduleService"/></property>
</bean>
</beans>
and web.xml is
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC '-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN' 'http://java.sun.com/dtd/web-app_2_3.dtd'>
<!--
- $Id: web.xml,v 1.1 2004/08/01 23:03:20 benalex Exp $
-->
<web-app>
<display-name>SampleProject</display-name>
<description>
Provides an example for using Spring framework
</description>
<!--
- Location of the XML file that defines the root application context
- Applied by ContextLoaderListener.
-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext-hibernate.xml</param-value>
</context-param>
<!--
- Loads the root application context of this web app at startup,
- by default from "/WEB-INF/applicationContext.xml".
- Use WebApplicationContextUtils.getWebApplicationContex t(servletContext)
- to access it anywhere in the web application, outside of the framework.
-->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListe ner</listener-class>
</listener>
<servlet>
<servlet-name>ws</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<!--
- Dispatcher servlet mapping for HTTP web services.
- (see ws-servlet.xml for the controllers).
-->
<servlet-mapping>
<servlet-name>ws</servlet-name>
<url-pattern>/ws/*</url-pattern>
</servlet-mapping>
<resource-env-ref>
<resource-env-ref-name>jms/topic</resource-env-ref-name>
<resource-env-ref-type>javax.jms.Topic</resource-env-ref-type>
</resource-env-ref>
<resource-ref>
<description>JMS Connection Factory</description>
<res-ref-name>jms/connectionFactory</res-ref-name>
<res-type>javax.jms.TopicConnectionFactory</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
</web-app>
jboss.xml is as
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jboss-web PUBLIC "-//JBoss//DTD Web Application 2.3V2//EN" "http://www.jboss.org/j2ee/dtd/jboss-web_3_2.dtd">
<jboss-web>
<context-root>SampleProjectModule</context-root>
<resource-env-ref>
<resource-env-ref-name>jms/topic</resource-env-ref-name>
<jndi-name>topic/EMRTopic</jndi-name>
</resource-env-ref>
<resource-ref>
<res-ref-name>jms/connectionFactory</res-ref-name>
<res-type>javax.jms.TopicConnectionFactory</res-type>
<jndi-name>java:/JmsXA</jndi-name>
<res-auth>Container</res-auth>
</resource-ref>
</jboss-web>
thouh not as relevant the DAO is as
package com.sequelsys.server.scheduling.dao;
import org.springframework.dao.*;
import org.springframework.orm.hibernate.support.*;
import com.sequelsys.common.model.scheduling.*;
public class HolidayScheduleDAO extends HibernateDaoSupport
implements IHolidayScheduleDAO {
public HolidayScheduleDAO() {
}
public HolidaysScheduleModel create(HolidaysScheduleModel holidaysScheduleModel) throws DataAccessException
{
Long seqNo = (Long) this.getHibernateTemplate().save(holidaysScheduleM odel);
holidaysScheduleModel.setSeqNum(seqNo);
return holidaysScheduleModel;
}
}
I am getting the following exception
19:07:16,021 ERROR [STDERR] org.springframework.jms.TransactionInProgressExcep tion: Should not be call from a XASession; nested exception is javax.jms.TransactionInProgressException: Should not be call from a XASession; nested exception is javax.jms.TransactionInProgressException: Should not be call from a XASession
19:07:16,021 ERROR [STDERR] javax.jms.TransactionInProgressException: Should not be call from a XASession
19:07:16,021 ERROR [STDERR] at org.jboss.mq.SpySession.commit(SpySession.java:410 )
19:07:16,021 ERROR [STDERR] at org.jboss.resource.adapter.jms.JmsSession.commit(J msSession.java:166)
19:07:16,068 ERROR [STDERR] at org.springframework.jms.core.JmsTemplate.doSend(Jm sTemplate.java:609)
19:07:16,068 ERROR [STDERR] at org.springframework.jms.core.JmsTemplate$2.doInJms (JmsTemplate.java:583)
19:07:16,068 ERROR [STDERR] at org.springframework.jms.core.JmsTemplate.execute(J msTemplate.java:548)
19:07:16,068 ERROR [STDERR] at org.springframework.jms.core.JmsTemplate.execute(J msTemplate.java:560)
19:07:16,068 ERROR [STDERR] at org.springframework.jms.core.JmsTemplate.send(JmsT emplate.java:581)
19:07:16,084 ERROR [STDERR] at com.sequelsys.server.scheduling.jms.JmsTopicSender .simpleSend(JmsTopicSender.java:13)
19:07:16,084 ERROR [STDERR] at com.sequelsys.server.scheduling.service.HolidaySch eduleService.createHolidaySchedule(HolidaySchedule Service.java:37)
19:07:16,084 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
19:07:16,084 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
19:07:16,084 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
19:07:16,084 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:324)
19:07:16,084 ERROR [STDERR] at org.springframework.aop.framework.AopProxyUtils.in vokeJoinpointUsingReflection(AopProxyUtils.java:61 )
19:07:16,084 ERROR [STDERR] at org.springframework.aop.framework.ReflectiveMethod Invocation.invokeJoinpoint(ReflectiveMethodInvocat ion.java:149)
19:07:16,084 ERROR [STDERR] at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :116)
19:07:16,084 ERROR [STDERR] at org.springframework.transaction.interceptor.Transa ctionInterceptor.invoke(TransactionInterceptor.jav a:56)
19:07:16,099 ERROR [STDERR] at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :138)
19:07:16,099 ERROR [STDERR] at org.springframework.aop.framework.JdkDynamicAopPro xy.invoke(JdkDynamicAopProxy.java:152)
19:07:16,099 ERROR [STDERR] at $Proxy30.createHolidaySchedule(Unknown Source)
19:07:16,099 ERROR [STDERR] at com.sequelsys.server.common.service.SchedulingFaca de.createHolidaySchedule(SchedulingFacade.java:37)
19:07:16,099 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
19:07:16,099 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
19:07:16,099 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
19:07:16,099 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:324)
19:07:16,099 ERROR [STDERR] at org.springframework.aop.framework.AopProxyUtils.in vokeJoinpointUsingReflection(AopProxyUtils.java:61 )
19:07:16,099 ERROR [STDERR] at org.springframework.aop.framework.JdkDynamicAopPro xy.invoke(JdkDynamicAopProxy.java:142)
19:07:16,099 ERROR [STDERR] at $Proxy30.createHolidaySchedule(Unknown Source)
19:07:16,099 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
19:07:16,099 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
19:07:16,099 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
19:07:16,099 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:324)
19:07:16,099 ERROR [STDERR] at org.springframework.remoting.support.RemoteInvocat ion.invoke(RemoteInvocation.java:179)
19:07:16,115 ERROR [STDERR] at org.springframework.remoting.support.DefaultRemote InvocationExecutor.invoke(DefaultRemoteInvocationE xecutor.java:32)
19:07:16,115 ERROR [STDERR] at org.springframework.remoting.support.RemoteInvocat ionBasedExporter.invoke(RemoteInvocationBasedExpor ter.java:70)
19:07:16,115 ERROR [STDERR] at org.springframework.remoting.support.RemoteInvocat ionBasedExporter.invokeAndCreateResult(RemoteInvoc ationBasedExporter.java:106)
19:07:16,115 ERROR [STDERR] at org.springframework.remoting.httpinvoker.HttpInvok erServiceExporter.handleRequest(HttpInvokerService Exporter.java:63)
19:07:16,115 ERROR [STDERR] at org.springframework.web.servlet.mvc.SimpleControll erHandlerAdapter.handle(SimpleControllerHandlerAda pter.java:44)
19:07:16,115 ERROR [STDERR] at org.springframework.web.servlet.DispatcherServlet. doService(DispatcherServlet.java:522)
19:07:16,115 ERROR [STDERR] at org.springframework.web.servlet.FrameworkServlet.s ervice(FrameworkServlet.java:321)
19:07:16,115 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet .java:853)
19:07:16,115 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:247)
19:07:16,115 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:193)
19:07:16,115 ERROR [STDERR] at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:256)
19:07:16,115 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline$Standard PipelineValveContext.invokeNext(StandardPipeline.j ava:643)
19:07:16,115 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:480)
19:07:16,115 ERROR [STDERR] at org.apache.catalina.core.ContainerBase.invoke(Cont ainerBase.java:995)
19:07:16,130 ERROR [STDERR] at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:191)
19:07:16,130 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline$Standard PipelineValveContext.invokeNext(StandardPipeline.j ava:643)
19:07:16,130 ERROR [STDERR] at org.jboss.web.tomcat.security.JBossSecurityMgrReal m.invoke(JBossSecurityMgrRealm.java:220)
19:07:16,130 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline$Standard PipelineValveContext.invokeNext(StandardPipeline.j ava:641)
19:07:16,130 ERROR [STDERR] at org.apache.catalina.valves.CertificatesValve.invok e(CertificatesValve.java:246)
19:07:16,130 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline$Standard PipelineValveContext.invokeNext(StandardPipeline.j ava:641)
19:07:16,130 ERROR [STDERR] at org.jboss.web.tomcat.tc4.statistics.ContainerStats Valve.invoke(ContainerStatsValve.java:76)
19:07:16,130 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline$Standard PipelineValveContext.invokeNext(StandardPipeline.j ava:641)
19:07:16,146 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:480)
19:07:16,146 ERROR [STDERR] at org.apache.catalina.core.ContainerBase.invoke(Cont ainerBase.java:995)
19:07:16,146 ERROR [STDERR] at org.apache.catalina.core.StandardContext.invoke(St andardContext.java:2417)
19:07:16,146 ERROR [STDERR] at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:180)
19:07:16,146 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline$Standard PipelineValveContext.invokeNext(StandardPipeline.j ava:643)
19:07:16,146 ERROR [STDERR] at org.apache.catalina.valves.ErrorDispatcherValve.in voke(ErrorDispatcherValve.java:171)
19:07:16,146 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline$Standard PipelineValveContext.invokeNext(StandardPipeline.j ava:641)
19:07:16,146 ERROR [STDERR] at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:172)
19:07:16,146 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline$Standard PipelineValveContext.invokeNext(StandardPipeline.j ava:641)
19:07:16,146 ERROR [STDERR] at org.jboss.web.tomcat.security.SecurityAssociationV alve.invoke(SecurityAssociationValve.java:65)
19:07:16,146 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline$Standard PipelineValveContext.invokeNext(StandardPipeline.j ava:641)
19:07:16,146 ERROR [STDERR] at org.apache.catalina.valves.AccessLogValve.invoke(A ccessLogValve.java:577)
19:07:16,146 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline$Standard PipelineValveContext.invokeNext(StandardPipeline.j ava:641)
19:07:16,162 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:480)
19:07:16,162 ERROR [STDERR] at org.apache.catalina.core.ContainerBase.invoke(Cont ainerBase.java:995)
19:07:16,162 ERROR [STDERR] at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:174)
19:07:16,162 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline$Standard PipelineValveContext.invokeNext(StandardPipeline.j ava:643)
19:07:16,162 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:480)
19:07:16,162 ERROR [STDERR] at org.apache.catalina.core.ContainerBase.invoke(Cont ainerBase.java:995)
19:07:16,162 ERROR [STDERR] at org.apache.coyote.tomcat4.CoyoteAdapter.service(Co yoteAdapter.java:197)
19:07:16,162 ERROR [STDERR] at org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:781)
19:07:16,162 ERROR [STDERR] at org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.processConnection(Http11Protocol.jav a:549)
19:07:16,162 ERROR [STDERR] at org.apache.tomcat.util.net.TcpWorkerThread.runIt(P oolTcpEndpoint.java:605)
19:07:16,162 ERROR [STDERR] at org.apache.tomcat.util.threads.ThreadPool$ControlR unnable.run(ThreadPool.java:677)
19:07:16,162 ERROR [STDERR] at java.lang.Thread.run(Thread.java:534)
I am quite sure that db part is working fine but jms somehow dont know the transaction. Please do it asap