メッセージがキューに入れられ、Hibernate を介して行われる DB を更新するためにメソッド呼び出しが行われるという要件があります。これを単一のトランザクションの一部として作成したいので、データベースの更新呼び出しが失敗した場合、JMS はロールバックし、メッセージをキューに入れません。設定してみましたが、何か足りないようです。どんな助けでも大歓迎です。
そして、私がJMSを呼び出しているメソッドとDAOは
@Transactional(rollbackFor = Exception.class)
public boolean retrieveBatchOrders(BatchPullCriteria batchPullCriteria) throws SQLException, IOException{
List<IntrmStrg> IntrmStrgOrderLst = iStorageDAO.retrieveByStoreId(batchPullCriteria);
List<IntrmStrg> IntrmStrgFinalLst = iStorageDAO.retrieveOrdersByStoreIdLst(batchPullCriteria,IntrmStrgOrderLst);
sendMsgToQueue.sendMessageToTarget(IntrmStrgFinalLst);
iStorageDAO.updateOrdersStatus(IntrmStrgFinalLst,batchPullCriteria.getRetrievedBy(),BATCHRTRVD);
return true;
}
@Transactional
public void updateOrdersStatus(List<IntrmStrg> IntrmStrgLst , String retrivedBy, String status ){
Date retriveDate = new Date();
Timestamp retriveDTimestamp = new Timestamp(retriveDate.getTime());
try{
for (Iterator<IntrmStrg> iterator = IntrmStrgLst.iterator(); iterator.hasNext();) {
IntrmStrg intrmStrg = (IntrmStrg) iterator.next();
intrmStrg.setRtrvdBy(retrivedBy);
intrmStrg.setRtrvdDt(retriveDTimestamp);
intrmStrg.setStts(status);
LOGGER.info("Updating Order Status with ID" + intrmStrg.getIntrmStrgId());
getHibernateTemplate().getSessionFactory().getCurrentSession().beginTransaction();
getHibernateTemplate().update(intrmStrg);
LOGGER.info("Updated Order Status with ID" + intrmStrg.getIntrmStrgId());
getHibernateTemplate().getSessionFactory().getCurrentSession().getTransaction().commit();
}
}
catch(HibernateException he)
{
getHibernateTemplate().getSessionFactory().getCurrentSession().getTransaction().rollback();
}
if (LOGGER.isDebugEnabled()) {
LOGGER.info("Order Status Updated");
}
}
アプリケーション.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<tx:annotation-driven transaction-manager="transactionManager"/>
<bean id="txManager" class="org.springframework.transaction.jta.JtaTransactionManager">
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="oracle.jdbc.OracleDriver" />
<property name="url"
value="" />
<property name="username" value="" />
<property name="password" value="" />
</bean>
<bean id="iStorageSessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource">
<ref local="dataSource" />
</property>
<property name="mappingDirectoryLocations">
<list>
<value>classpath:org/entity</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
<prop key="hibernate.default_schema">DEV1</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager"
lazy-init="true">
<property name="dataSource" ref="dataSource" />
</bean>
<!-- -DAO Beans -->
<bean id="storageDAO" class="org.kp.oppr.iStorage.dao.IStorageDAOImpl" >
<property name="sessionFactory">
<ref local="iStorageSessionFactory" />
</property>
</bean>
<!-- Service Beans -->
<bean id="iStorageService" class="org.kp.oppr.iStorage.services.IStorageServiceImpl" >
</bean>
<!-- BROKER CONNECTION SETTING FOR TARXHB00 -->
<bean id="jmsFactory" class="com.ibm.mq.jms.MQQueueConnectionFactory">
<property name="hostName" value="${mq.conn.hostName}" />
<property name="port" value="${mq.conn.hostPort}" />
<property name="queueManager" value="${mq.conn.queueManager}" />
<property name="channel" value="${mq.conn.channel}" />
<property name="transportType" value="${mq.conn.transportType}" />
</bean>
<bean id="jmsFactorySecurity"
class="org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter">
<property name="targetConnectionFactory" ref="jmsFactory" />
<property name="username" value=" " />
<property name="password" value=" " />
</bean>
<bean id="jmsQueueSender" class="org.kp.oppr.storage.jms.JmsQueueSender">
<property name="connectionFactory" ref="jmsFactorySecurity"></property>
</bean>
<bean id="SendMsgToQueue" class="org.kp.oppr.storage.jms.SendMsgToQueue">
<property name="queueNamePrfix" value="${QUEUE_PREFIX}"></property>
<property name="queueNameSufix" value="${QUEUE_SUFFIX}"></property>
</bean>
<bean id="iStorageConfig" class="org.kp.oppr.storage.config.storageConfig">
<property name="maxNumberofOrders" value="${MAX_ORDER_COUNT}"></property>
</bean>
</beans>