I have a web application set up with MyBatis and Spring, but it doesn't seem to be using any transactions. Here's the configuration:
applicationContext.xml:
<tx:annotation-driven />
<!-- <tx:jta-transaction-manager /> --> <!-- using WebSphere 7 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="jdbc/my_datasource" />
</bean>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="configLocation" value="WEB-INF/mybatis-config.xml" />
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="testDAO" class="org.mybatis.spring.mapper.MapperFactoryBean">
<property name="mapperInterface" value="com.lmig.TestDAO" />
<property name="sqlSessionFactory" ref="sqlSessionFactory" />
</bean>
Sample bean method with transaction definition:
#Transactional(propagation = Propagation.REQUIRED)
public void testDelete() {
testDAO.firstDelete(); //always successful
testDAO.secondDelete(); //always throws SQLServerException
}
TestDAO:
public interface TestDAO {
public void firstDelete();
public void secondDelete();
}
Server debug log:
[11/17/11 16:42:07:998 PST] 0000002b SystemOut O DEBUG [org.mybatis.spring.SqlSessionUtils] Creating SqlSession with JDBC Connection [com.ibm.ws.rsadapter.jdbc.WSJdbcConnection#34ba34ba]
[11/17/11 16:42:07:999 PST] 0000002b SystemOut O DEBUG [java.sql.Connection] ooo Connection Opened
[11/17/11 16:42:08:001 PST] 0000002b SystemOut O DEBUG [org.mybatis.spring.transaction.SpringManagedTransaction] JDBC Connection [com.ibm.ws.rsadapter.jdbc.WSJdbcConnection#34ba34ba] will be managed by Spring
[11/17/11 16:42:08:005 PST] 0000002b SystemOut O DEBUG [org.mybatis.spring.SqlSessionUtils] Registering transaction synchronization for SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession#74247424]
[11/17/11 16:42:08:025 PST] 0000002b SystemOut O DEBUG [java.sql.PreparedStatement] ==> Executing: delete from test1
[11/17/11 16:42:08:025 PST] 0000002b SystemOut O DEBUG [java.sql.PreparedStatement] ==> Parameters:
[11/17/11 16:42:08:097 PST] 0000002b SystemOut O DEBUG [org.mybatis.spring.SqlSessionUtils] Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession#74247424]
[11/17/11 16:42:08:099 PST] 0000002b SystemOut O DEBUG [org.mybatis.spring.SqlSessionUtils] Transaction synchronization committing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession#74247424]
[11/17/11 16:42:08:123 PST] 0000002b SystemOut O DEBUG [org.mybatis.spring.SqlSessionUtils] Transaction synchronization closing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession#74247424]
[11/17/11 16:42:08:136 PST] 0000002b SystemOut O DEBUG [org.mybatis.spring.SqlSessionUtils] Creating SqlSession with JDBC Connection [com.ibm.ws.rsadapter.jdbc.WSJdbcConnection#17351735]
[11/17/11 16:42:08:137 PST] 0000002b SystemOut O DEBUG [java.sql.Connection] ooo Connection Opened
[11/17/11 16:42:08:138 PST] 0000002b SystemOut O DEBUG [org.mybatis.spring.transaction.SpringManagedTransaction] JDBC Connection [com.ibm.ws.rsadapter.jdbc.WSJdbcConnection#17351735] will be managed by Spring
[11/17/11 16:42:08:139 PST] 0000002b SystemOut O DEBUG [org.mybatis.spring.SqlSessionUtils] Registering transaction synchronization for SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession#1d871d87]
[11/17/11 16:42:08:145 PST] 0000002b SystemOut O DEBUG [java.sql.PreparedStatement] ==> Executing: delete from test2
[11/17/11 16:42:08:146 PST] 0000002b SystemOut O DEBUG [java.sql.PreparedStatement] ==> Parameters:
[11/17/11 16:42:08:490 PST] 0000002b XmlBeanDefini I org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions Loading XML bean definitions from class path resource [org/springframework/jdbc/support/sql-error-codes.xml]
[11/17/11 16:42:08:554 PST] 0000002b SQLErrorCodes I org.springframework.jdbc.support.SQLErrorCodesFactory <init> SQLErrorCodes loaded: [DB2, Derby, H2, HSQL, Informix, MS-SQL, MySQL, Oracle, PostgreSQL, Sybase]
[11/17/11 16:42:08:560 PST] 0000002b SystemOut O DEBUG [org.mybatis.spring.SqlSessionUtils] Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession#1d871d87]
[11/17/11 16:42:08:597 PST] 0000002b SystemOut O DEBUG [org.mybatis.spring.SqlSessionUtils] Transaction synchronization closing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession#1d871d87]
...SQLServerException follows...
Since secondDelete() throws an exception, the entire transaction would be expected to roll back. However, this isn't the case, and the firstDelete() is still committed. I've tried all combinations of the transaction manager config (Spring-managed, app server-managed, both) but I keep getting the same results. Any idea what I'm doing wrong?
I'm using Mybatis 3, Spring 3 on WebSphere 7 with SQL Server 2005 as the DB.
I figured this out: my testDelete() method wasn't a Spring-managed bean, so it wasn't participating in Spring-managed transactions. I changed my configuration to this, and now it's working.
Related
I'm trying to handle errors using the int:poller, I defined an error-channel on the poller when an error occurs the ErrorHandler invoked, but it still executed in a loop and
block the principal process that handle the next correct message.
Here's my config any ideas?
<int:outbound-channel-adapter ref="cvsMessageHandler" method="handleMessage" channel="cvsInputChannel"/>
<int:poller max-messages-per-poll="1" id="defaultPoller" default="true" fixed-rate="5000"
error-channel="cvsErrorChannel">
<int:transactional transaction-manager="transactionManager" />
</int:poller>
<bean id="cvsMessageHandler" class="com.cvs.ws.wrapper.MessageHandler">
</bean>
<int:channel id="cvsErrorChannel"/>
<bean id="cvsErrorMessageHandler" class="com.eplatform.transverse.cvs.ws.service.ErrorHandler">
<property name="eventService" ref="cvsEventService"/>
<property name="eventFactory" ref="cvsEventFactory"/>
</bean>
<int:chain input-channel="cvsErrorChannel">
<int:service-activator ref="cvsErrorMessageHandler" method="handleMessage"/>
</int:chain>
<stream:stderr-channel-adapter channel="errorChannel" append-newline="true"/>
<int:channel id="csdbInputChannel">
<int:queue message-store="messageStore"/>
</int:channel>
<bean id="csdbService" class="com.renault.eplatform.transverse.datapower.csdb.ws.service.CsdbService">
<property name="channel" ref="csdbInputChannel"/>
</bean>
<bean id="csdbWrapper" class="com.renault.eplatform.transverse.datapower.csdb.ws.wrapper.CsdbWrapper">
<property name="httpClient">
<bean class="com.fullsix.framework.net.http.HttpClientFactoryBean"/>
</property>
<property name="url" value="${www}"/>
<property name="enumCountry" ref="currentCountry"/>
<property name="datapowerLoggingService" ref="dxxx"/>
<property name="password" value="${dwwww}"/>
<property name="socketTimeout" value="20000"/>
<property name="timeout" value="20000"/>
</bean>
201803-08 15:34:55,546 ERROR [ErrorHandler.java:28] - Try to fix data
on tables DATAPOWER_CSDB_MESSAGE_GROUP and DATAPOWER_CSDB_MESSAGE
201803-08 15:34:55,547 DEBUG
[AbstractReplyProducingMessageHandler.java:107]
- handler 'ServiceActivator for [org.springframework.integration.handler.MethodInvokingMessageProcessor#4cc7014c]'
produced no reply for request Message:
[Payload=java.lang.NullPointerException][Headers={timestamp=1520519695543,
id=b71d066b-a8e5-4fa3-8b87-a8c1d9e57587}]
201803-08 15:34:55,547
DEBUG [AbstractMessageChannel.java:237] - postSend (sent=true) on
channel 'csdbErrorChannel', message:
[Payload=java.lang.NullPointerException][Headers={timestamp=1520519695543,
id=b71d066b-a8e5-4fa3-8b87-a8c1d9e57587}]
201803-08 15:35:00,515
DEBUG [AbstractPlatformTransactionManager.java:365] - Creating new
transaction with name
201803-08 15:35:00,516 DEBUG
[SessionImpl.java:265] - opened session at timestamp: 15205197005
201803-08 15:35:00,517 DEBUG [HibernateTransactionManager.java:493] -
Opened new Session [org.hibernate.impl.SessionImpl#7e350225] for
Hibernate transaction
201803-08 15:35:00,517 DEBUG
[HibernateTransactionManager.java:504] - Preparing JDBC Connection of
Hibernate Session [org.hibernate.impl.SessionImpl#7e350225]
201803-08
15:35:00,517 DEBUG [JDBCTransaction.java:78] - begin
201803-08
15:35:00,518 DEBUG [ConnectionManager.java:444] - opening JDBC
connection
201803-08 15:35:00,518 DEBUG [JDBCTransaction.java:83] -
current autocommit status: true
201803-08 15:35:00,519 DEBUG
[JDBCTransaction.java:86] - disabling autocommit
201803-08
15:35:00,519 DEBUG [HibernateTransactionManager.java:569] - Exposing
Hibernate transaction as JDBC transaction
[jdbc:oracle:thin:#//active-db-valid:1521/rsite, UserName=RSITE_ES,
Oracle JDBC driver]
201803-08 15:35:00,520 DEBUG
[JdbcTemplate.java:635] - Executing prepared SQL query
201803-08
15:35:00,520 DEBUG [JdbcTemplate.java:570] - Executing prepared SQL
statement [SELECT COUNT(MESSAGE_ID) from DATAPOWER_CSDB_MESSAGE_GROUP
where GROUP_KEY=? AND REGION=?]
201803-08 15:35:00,523 DEBUG
[JdbcTemplate.java:635] - Executing prepared SQL query
201803-08
15:35:00,523 DEBUG [JdbcTemplate.java:570] - Executing prepared SQL
statement [SELECT MESSAGE_ID, CREATED_DATE from
DATAPOWER_CSDB_MESSAGE_GROUP where GROUP_KEY=? and REGION=? order by
UPDATED_DATE]
201803-08 15:35:00,525 DEBUG [JdbcTemplate.java:635] -
Executing prepared SQL query
201803-08 15:35:00,526 DEBUG
[JdbcTemplate.java:570] - Executing prepared SQL statement [SELECT
MESSAGE_ID, CREATED_DATE, MESSAGE_BYTES from DATAPOWER_CSDB_MESSAGE
where MESSAGE_ID=? and REGION=?]
201803-08 15:35:00,528 DEBUG
[DefaultLobHandler.java:117] - Returning BLOB as bytes
201803-08
15:35:00,529 DEBUG [AbstractPlatformTransactionManager.java:843] -
Initiating transaction rollback
201803-08 15:35:00,529 DEBUG
[HibernateTransactionManager.java:672] - Rolling back Hibernate
transaction on Session [org.hibernate.impl.SessionImpl#7e350225]
201803-08 15:35:00,530 DEBUG [JDBCTransaction.java:182] - rollback
201803-08 15:35:00,531 DEBUG [JDBCTransaction.java:223] - re-enabling
autocommit
201803-08 15:35:00,531 DEBUG [JDBCTransaction.java:193] -
rolled back JDBC Connection
201803-08 15:35:00,531 DEBUG
[ConnectionManager.java:325] - transaction completed on session with
on_close connection release mode; be sure to close the session to
release JDBC resources!
201803-08 15:35:00,532 DEBUG
[HibernateTransactionManager.java:734] - Closing Hibernate Session
[org.hibernate.impl.SessionImpl#7e350225] after transaction
201803-08
15:35:00,532 DEBUG [SessionFactoryUtils.java:800] - Closing Hibernate
Session
201803-08 15:35:00,533 DEBUG [ConnectionManager.java:464] -
releasing JDBC connection [ (open PreparedStatements: 0, globally: 0)
(open ResultSets: 0, globally: 0)]
201803-08 15:35:00,533 DEBUG
[ConnectionManager.java:325] - transaction completed on session with
on_close connection release mode; be sure to close the session to
release JDBC resources!
201803-08 15:35:00,534 DEBUG
[AbstractMessageChannel.java:224] - preSend on channel
'csdbErrorChannel', message:
[Payload=java.lang.NullPointerException][Headers={timestamp=1520519700534,
id=fe974a6c-2351-4b95-ac6f-b98a0c02a7b3}]
201803-08 15:35:00,534
DEBUG [AbstractMessageHandler.java:67] -
org.springframework.integration.handler.MessageHandlerChain#0 received
message:
[Payload=java.lang.NullPointerException][Headers={timestamp=1520519700534,
id=fe974a6c-2351-4b95-ac6f-b98a0c02a7b3}]
201803-08 15:35:00,535
DEBUG [AbstractMessageHandler.java:67] - ServiceActivator for
[org.springframework.integration.handler.MethodInvokingMessageProcessor#4cc7014c]
received message:
[Payload=java.lang.NullPointerException][Headers={timestamp=1520519700534,
id=fe974a6c-2351-4b95-ac6f-b98a0c02a7b3}]
201803-08 15:35:00,535
INFO [ErrorHandler.java:25] - Error message handled
201803-08
15:35:00,536 ERROR [ErrorHandler.java:27] -
java.lang.NullPointerException
201803-08 15:35:00,536 ERROR
[ErrorHandler.java:28] - Try to fix data on tables
DATAPOWER_CSDB_MESSAGE_GROUP and DATAPOWER_CSDB_MESSAGE*
*
I am developing Spring Batch MongoDB to XML example. I was successfully developed the application, but I dont see data is getting written into the XML file. Could you please guide me what is the issue ? I dont see any working example yet on the web.
job-report.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:batch="http://www.springframework.org/schema/batch"
xmlns:task="http://www.springframework.org/schema/task"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
xsi:schemaLocation="http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch.xsd">
<!-- Actual Job -->
<batch:job id="reportJob">
<batch:step id="step1">
<batch:tasklet>
<batch:chunk reader="mongodbItemReader" writer="xmlItemWriter" commit-interval="1">
</batch:chunk>
</batch:tasklet>
</batch:step>
</batch:job>
<bean id="mongodbItemReader" class="org.springframework.batch.item.data.MongoItemReader">
<property name="template" ref="mongoTemplate" />
<property name="collection" value="report" />
<property name="targetType" value="com.mkyong.model.Report" />
<property name="query" value="{'_id':{$gt:0} }" />
<property name="sort">
<util:map>
<entry key="id" value="#{T(org.springframework.data.domain.Sort.Direction).ASC}" />
</util:map>
</property>
</bean>
<bean id="xmlItemWriter" class="org.springframework.batch.item.xml.StaxEventItemWriter">
<property name="resource" value="classpath:xml/report.xml" />
<property name="marshaller" ref="reportUnMarshaller" />
<property name="rootTagName" value="record" />
</bean>
<bean id="reportUnMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="classesToBeBound">
<value>com.mkyong.model.Report</value>
</property>
</bean>
</beans>
App.java
public class App {
public static void main(String[] args) {
String[] springConfig = { "database.xml", "context.xml", "job-report.xml" };
ApplicationContext context = new ClassPathXmlApplicationContext(springConfig);
JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher");
Job job = (Job) context.getBean("reportJob");
try {
JobExecution execution = jobLauncher.run(job, new JobParameters());
System.out.println("Exit Status : " + execution.getStatus());
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("Done");
}
}
Logs from console:
14:58:52.487 [main] DEBUG o.s.b.c.s.c.StepContextRepeatCallback - Preparing chunk execution for StepContext: org.springframework.batch.core.scope.context.StepContext#aa594b
14:58:52.487 [main] DEBUG o.s.b.c.s.c.StepContextRepeatCallback - Chunk execution starting: queue size=0
14:58:52.487 [main] DEBUG o.s.b.s.t.ResourcelessTransactionManager - Creating new transaction with name [null]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT
14:58:52.487 [main] DEBUG o.s.b.repeat.support.RepeatTemplate - Starting repeat context.
14:58:52.487 [main] DEBUG o.s.b.repeat.support.RepeatTemplate - Repeat operation about to start at count=1
14:58:52.488 [main] DEBUG o.s.data.mongodb.core.MongoTemplate - find using query: { "_id" : { "$gt" : 0}} fields: null for class: class com.mkyong.model.Report in collection: report
14:58:52.488 [main] DEBUG o.s.data.mongodb.core.MongoDbUtils - Getting Mongo Database name=[yourdb]
14:58:52.488 [main] DEBUG o.s.data.mongodb.core.MongoDbUtils - Registering Spring transaction synchronization for MongoDB instance yourdb.
14:58:52.488 [main] DEBUG org.mongodb.driver.protocol.query - Sending query of namespace yourdb.report on connection [connectionId{localValue:3, serverValue:53}] to server 127.0.0.1:27017
14:58:52.489 [main] DEBUG org.mongodb.driver.protocol.query - Query completed
14:58:52.489 [main] DEBUG o.s.b.repeat.support.RepeatTemplate - Repeat is complete according to policy and result value.
14:58:52.489 [main] DEBUG o.s.b.c.s.item.ChunkOrientedTasklet - Inputs not busy, ended: true
14:58:52.489 [main] DEBUG o.s.b.core.step.tasklet.TaskletStep - Applying contribution: [StepContribution: read=0, written=0, filtered=0, readSkips=0, writeSkips=0, processSkips=0, exitStatus=EXECUTING]
14:58:52.489 [main] DEBUG o.s.b.s.t.ResourcelessTransactionManager - Participating in existing transaction
14:58:52.490 [main] DEBUG o.s.b.core.step.tasklet.TaskletStep - Saving step execution before commit: StepExecution: id=1, version=5, name=step1, status=STARTED, exitStatus=EXECUTING, readCount=4, filterCount=0, writeCount=4 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=5, rollbackCount=0, exitDescription=
14:58:52.490 [main] DEBUG o.s.b.s.t.ResourcelessTransactionManager - Participating in existing transaction
14:58:52.491 [main] DEBUG o.s.b.s.t.ResourcelessTransactionManager - Initiating transaction commit
14:58:52.491 [main] DEBUG o.s.b.s.t.ResourcelessTransactionManager - Committing resourceless transaction on [org.springframework.batch.support.transaction.ResourcelessTransactionManager$ResourcelessTransaction#a8ee09]
14:58:52.492 [main] DEBUG o.s.b.repeat.support.RepeatTemplate - Repeat is complete according to policy and result value.
14:58:52.492 [main] DEBUG o.s.batch.core.step.AbstractStep - Step execution success: id=1
14:58:52.492 [main] DEBUG o.s.b.s.t.ResourcelessTransactionManager - Creating new transaction with name [org.springframework.batch.core.repository.support.SimpleJobRepository.updateExecutionContext]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT
14:58:52.492 [main] DEBUG o.s.b.s.t.ResourcelessTransactionManager - Initiating transaction commit
14:58:52.492 [main] DEBUG o.s.b.s.t.ResourcelessTransactionManager - Committing resourceless transaction on [org.springframework.batch.support.transaction.ResourcelessTransactionManager$ResourcelessTransaction#5b3037]
14:58:52.492 [main] DEBUG o.s.b.s.t.ResourcelessTransactionManager - Creating new transaction with name [org.springframework.batch.core.repository.support.SimpleJobRepository.update]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT
14:58:52.494 [main] DEBUG o.s.b.s.t.ResourcelessTransactionManager - Initiating transaction commit
14:58:52.494 [main] DEBUG o.s.b.s.t.ResourcelessTransactionManager - Committing resourceless transaction on [org.springframework.batch.support.transaction.ResourcelessTransactionManager$ResourcelessTransaction#baa89c]
14:58:52.495 [main] DEBUG o.s.batch.core.step.AbstractStep - Step execution complete: StepExecution: id=1, version=7, name=step1, status=COMPLETED, exitStatus=COMPLETED, readCount=4, filterCount=0, writeCount=4 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=5, rollbackCount=0
14:58:52.495 [main] DEBUG o.s.b.s.t.ResourcelessTransactionManager - Creating new transaction with name [org.springframework.batch.core.repository.support.SimpleJobRepository.updateExecutionContext]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT
14:58:52.496 [main] DEBUG o.s.b.s.t.ResourcelessTransactionManager - Initiating transaction commit
14:58:52.496 [main] DEBUG o.s.b.s.t.ResourcelessTransactionManager - Committing resourceless transaction on [org.springframework.batch.support.transaction.ResourcelessTransactionManager$ResourcelessTransaction#1f2ebae]
14:58:52.496 [main] DEBUG o.s.b.c.job.flow.support.SimpleFlow - Completed state=reportJob.step1 with status=COMPLETED
14:58:52.496 [main] DEBUG o.s.b.c.job.flow.support.SimpleFlow - Handling state=reportJob.end1
14:58:52.496 [main] DEBUG o.s.b.c.job.flow.support.SimpleFlow - Completed state=reportJob.end1 with status=COMPLETED
14:58:52.497 [main] DEBUG o.s.batch.core.job.AbstractJob - Job execution complete: JobExecution: id=0, version=1, startTime=Tue Jan 10 14:58:52 IST 2017, endTime=null, lastUpdated=Tue Jan 10 14:58:52 IST 2017, status=COMPLETED, exitStatus=exitCode=COMPLETED;exitDescription=, job=[JobInstance: id=0, version=0, Job=[reportJob]], jobParameters=[{}]
14:58:52.497 [main] DEBUG o.s.b.s.t.ResourcelessTransactionManager - Creating new transaction with name [org.springframework.batch.core.repository.support.SimpleJobRepository.update]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT
14:58:52.501 [main] DEBUG o.s.b.s.t.ResourcelessTransactionManager - Initiating transaction commit
14:58:52.501 [main] DEBUG o.s.b.s.t.ResourcelessTransactionManager - Committing resourceless transaction on [org.springframework.batch.support.transaction.ResourcelessTransactionManager$ResourcelessTransaction#498b0]
14:58:52.501 [main] INFO o.s.b.c.l.support.SimpleJobLauncher - Job: [FlowJob: [name=reportJob]] completed with the following parameters: [{}] and the following status: [COMPLETED]
Exit Status : COMPLETED
Done
In this example, I do need to manually create xml/report.xml into the classpath. Ideally it should be automatic. Right?
I got the solution to this problem from the link: Complex XML using Spring Batch; StaxEventItemWriter ; Jaxb2Marshaller. Also I should use
<bean id="xmlItemWriter" class="org.springframework.batch.item.xml.StaxEventItemWriter">
<property name="resource" value="file:outputs/report.xml" />
<property name="encoding" value="ISO-8859-1" />
<property name="version" value="1.0" />
<property name="marshaller" ref="reportMarshaller" />
<property name="rootTagName" value="record" />
</bean>
EDIT - I have checked this combinations so it seems there's something wrong with Hibernate 4:
Spring 4 + JPA + Hibernate 4 -> Exception
Spring 4 + Hibernate 4 -> Exception
Spring 4 + JPA + Hibernate 3 -> OK
Spring 4 + Hibernate 3 -> OK
Spring 3 + JPA - Hibernate 4 -> Exception
Spring 3 + JPA - Hibernate 3 -> OK
Spring 3 + Hibernate 3 -> OK
I have recently upgraded an application from Spring 3.2/Hibernate 3.6.10 to Spring 4.0.3 + Hibernate 4.1.12. My environment is IBM Websphere 8.0.0.7 and DB2 and the application is configured to use a XA Datasource.
The point is that at the first database call (subsequent calls are always OK) I am getting this error:
#Transactional(readOnly = true)
public Foo loadFoo(int id) {
LOG.debug("load {}", id);
FooEntity fe = fooDAO.findOne(id);
...
}
org.springframework.beans.factory.support.DefaultListableBeanFactory DEBUG - Returning cached instance of singleton bean 'fooRestController'
org.springframework.beans.factory.support.DefaultListableBeanFactory DEBUG - Returning cached instance of singleton bean 'globalControllerAdvice'
org.springframework.beans.factory.support.DefaultListableBeanFactory DEBUG - Returning cached instance of singleton bean 'org.springframework.transaction.interceptor.TransactionInterceptor#0'
org.springframework.beans.factory.support.DefaultListableBeanFactory DEBUG - Returning cached instance of singleton bean 'transactionManager'
org.springframework.transaction.jta.WebSphereUowTransactionManager DEBUG - Creating new transaction with name [null]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT,readOnly; ''
org.springframework.transaction.jta.WebSphereUowTransactionManager DEBUG - Invoking WebSphere UOW action: type=1, join=false
org.springframework.data.repository.core.support.TransactionalRepositoryProxyPostProcessor$CustomAnnotationTransactionAttributeSource DEBUG - Adding transactional method 'findOne' with attribute: PROPAGATION_REQUIRED,ISOLATION_DEFAULT,readOnly; ''
org.springframework.beans.factory.support.DefaultListableBeanFactory DEBUG - Returning cached instance of singleton bean 'transactionManager'
org.springframework.transaction.jta.WebSphereUowTransactionManager DEBUG - Creating new transaction with name [null]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT,readOnly; ''
org.springframework.transaction.jta.WebSphereUowTransactionManager DEBUG - Invoking WebSphere UOW action: type=1, join=true
org.springframework.orm.jpa.EntityManagerFactoryUtils DEBUG - Opening JPA EntityManager
org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl DEBUG - Skipping JTA sync registration due to auto join checking
org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl DEBUG - successfully registered Synchronization
org.hibernate.ejb.AbstractEntityManagerImpl DEBUG - Looking for a JTA transaction to join
org.springframework.orm.jpa.EntityManagerFactoryUtils DEBUG - Registering transaction synchronization for JPA EntityManager
org.hibernate.loader.Loader DEBUG - Loading entity: [com.mycompany.spring4.entity.FooEntity#17027]
org.hibernate.engine.jdbc.internal.LogicalConnectionImpl DEBUG - Obtaining JDBC connection
org.hibernate.engine.jdbc.internal.LogicalConnectionImpl DEBUG - Obtained JDBC connection
DSRA0304E: XAException occurred. XAException contents and details are: "".
DSRA0302E: XAException occurred. Error code is: XAER_OUTSIDE (-9). Exception is: XAER_OUTSIDE
J2CA0027E: An exception occurred while invoking start on an XA Resource Adapter from DataSource jdbc/LOCDBD1_XA, within transaction ID {XidImpl: formatId(57415344), gtrid_length(36), bqual_length(54),
data(0000014517a4c063000000015e7f81b4c90865e6b88e167905e5d2ed67f44ed6409cba5c0000014517a4c063000000015e7f81b4c90865e6b88e167905e5d2ed67f44ed6409cba5c000000010000000000000000000000000001)} : com.ibm.db2.jcc.c.zh: XAER_OUTSIDE
Caused by: javax.transaction.RollbackException: XAResource working outside transaction
at com.ibm.tx.jta.impl.RegisteredResources.startRes(RegisteredResources.java:1019)
at com.ibm.ws.tx.jta.RegisteredResources.enlistResource(RegisteredResources.java:1113)
at com.ibm.ws.tx.jta.TransactionImpl.enlistResource(TransactionImpl.java:2214)
at com.ibm.tx.jta.impl.EmbeddableTranManagerSet.enlist(EmbeddableTranManagerSet.java:150)
at com.ibm.ejs.j2c.XATransactionWrapper.enlist(XATransactionWrapper.java:727)
... 140 more
Caused by: com.ibm.db2.jcc.c.zh: XAER_OUTSIDE
at com.ibm.db2.jcc.b.bc.a(bc.java:1651)
at com.ibm.db2.jcc.b.bc.start(bc.java:1530)
at com.ibm.ws.rsadapter.spi.WSRdbXaResourceImpl.start(WSRdbXaResourceImpl.java:1525)
at com.ibm.ejs.j2c.XATransactionWrapper.start(XATransactionWrapper.java:1475)
at com.ibm.ws.Transaction.JTA.JTAResourceBase.start(JTAResourceBase.java:153)
at com.ibm.tx.jta.impl.RegisteredResources.startRes(RegisteredResources.java:1002)
... 144 more
This is the log trace of the second and successful call :
org.springframework.beans.factory.support.DefaultListableBeanFactory DEBUG - Returning cached instance of singleton bean 'fooRestController'
org.springframework.beans.factory.support.DefaultListableBeanFactory DEBUG - Returning cached instance of singleton bean 'globalControllerAdvice'
org.springframework.beans.factory.support.DefaultListableBeanFactory DEBUG - Returning cached instance of singleton bean 'transactionManager'
org.springframework.transaction.jta.WebSphereUowTransactionManager DEBUG - Creating new transaction with name [null]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT,readOnly; ''
org.springframework.transaction.jta.WebSphereUowTransactionManager DEBUG - Invoking WebSphere UOW action: type=1, join=false
org.springframework.beans.factory.support.DefaultListableBeanFactory DEBUG - Returning cached instance of singleton bean 'transactionManager'
org.springframework.transaction.jta.WebSphereUowTransactionManager DEBUG - Creating new transaction with name [null]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT,readOnly; ''
org.springframework.transaction.jta.WebSphereUowTransactionManager DEBUG - Invoking WebSphere UOW action: type=1, join=true
org.springframework.orm.jpa.EntityManagerFactoryUtils DEBUG - Opening JPA EntityManager
org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl DEBUG - Skipping JTA sync registration due to auto join checking
org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl DEBUG - successfully registered Synchronization
org.hibernate.ejb.AbstractEntityManagerImpl DEBUG - Looking for a JTA transaction to join
org.springframework.orm.jpa.EntityManagerFactoryUtils DEBUG - Registering transaction synchronization for JPA EntityManager
org.hibernate.loader.Loader DEBUG - Loading entity: [com.mycompany.spring4.entity.FooEntity#17027]
org.hibernate.engine.jdbc.internal.LogicalConnectionImpl DEBUG - Obtaining JDBC connection
org.hibernate.engine.jdbc.internal.LogicalConnectionImpl DEBUG - Obtained JDBC connection
org.hibernate.loader.Loader DEBUG - Result set row: 0
org.hibernate.loader.Loader DEBUG - Result row: EntityKey[com.mycompany.spring4.entity.FooEntity#17027]
org.hibernate.engine.internal.TwoPhaseLoad DEBUG - Resolving associations for [com.mycompany.spring4.entity.FooEntity#17027]
org.hibernate.engine.internal.TwoPhaseLoad DEBUG - Done materializing entity [com.mycompany.spring4.entity.FooEntity#17027]
org.hibernate.engine.jdbc.internal.LogicalConnectionImpl DEBUG - Releasing JDBC connection
org.hibernate.engine.jdbc.internal.LogicalConnectionImpl DEBUG - Released JDBC connection
org.hibernate.engine.jdbc.internal.proxy.ConnectionProxyHandler DEBUG - HHH000163: Logical connection releasing its physical connection
org.hibernate.loader.Loader DEBUG - Done entity load
org.springframework.transaction.jta.WebSphereUowTransactionManager DEBUG - Returned from WebSphere UOW action: type=1, join=true
org.springframework.orm.jpa.EntityManagerFactoryUtils DEBUG - Closing JPA EntityManager
org.hibernate.engine.jdbc.internal.LogicalConnectionImpl DEBUG - Aggressively releasing JDBC connection
org.springframework.transaction.jta.WebSphereUowTransactionManager DEBUG - Returned from WebSphere UOW action: type=1, join=false
The relevant part of my cfg is:
<bean id="mainEntityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="mainPersistenceUnit"/>
<property name="jtaDataSource" ref="mainDataSource"/>
<property name="packagesToScan" ref="packages-mainEntityManagerFactory"/>
<property name="jpaProperties">
<props>
<prop key="hibernate.transaction.jta.platform">org.hibernate.service.jta.platform.internal.WebSphereExtendedJtaPlatform</prop>
<prop key="hibernate.current_session_context_class">jta</prop>
<prop key="hibernate.transaction.factory_class">org.hibernate.engine.transaction.internal.jta.CMTTransactionFactory</prop>
</props>
</property>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/>
</property>
<property name="jpaDialect">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect"/>
</property>
</bean>
<tx:annotation-driven order="0" />
<bean name="transactionManager" class="org.springframework.transaction.jta.WebSphereUowTransactionManager">
<property name="allowCustomIsolationLevels" value="true" />
</bean>
Any idea why it fails the first time it's called?
The problem solved by itself upgrading to Spring 4.1.6 and Hibernate 4.2.19. I guess it was a Hibernate-related issue.
I have created a basic Spring applicatin to read from Oracle AQ. I am experiencing following issues. Kindly help me on this
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
2012-02-08 13:26:37,700 DEBUG [org.springframework.data.jdbc.jms.listener.oracle.AdtMessageListenerContainer] - <Received message of type [class oracle.jms.AQjmsAdtMessage] from consumer [oracle.jms.AQjmsConsumer#1989b5] of transactional session [oracle.jms.AQjmsSession#189c036]>
2012-02-08 13:26:37,700 DEBUG [org.springframework.data.jdbc.support.oracle.BeanPropertyStructMapper] - <Mapping column 'id' to property 'id' of type class java.math.BigDecimal>
2012-02-08 13:26:37,700 DEBUG [org.springframework.data.jdbc.support.oracle.BeanPropertyStructMapper] - <Mapping column 'type_cd' to property 'type_cd' of type class java.lang.String>
2012-02-08 13:26:37,700 INFO [com.test.oracle.aq.ProductDelegate] - <Product [id=6, type_cd=Test Product Code]>
2012-02-08 13:26:37,715 DEBUG [org.springframework.jdbc.core.JdbcTemplate] - <Executing SQL update [INSERT INTO Product(id, type_cd) values(6, 'Test Product Code')]>
2012-02-08 13:26:37,731 DEBUG [org.springframework.jdbc.core.JdbcTemplate] - <SQL update affected 1 rows>
2012-02-08 13:26:57,295 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Initiating transaction commit>
2012-02-08 13:26:57,295 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Committing JDBC transaction on Connection [oracle.jdbc.driver.T4CConnection#1860038]>
2012-02-08 13:26:57,295 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Releasing JDBC Connection [oracle.jdbc.driver.T4CConnection#1860038] after transaction>
2012-02-08 13:26:57,295 DEBUG [org.springframework.jdbc.datasource.DataSourceUtils] - <Returning JDBC Connection to DataSource>
4)- Why it is making soo many tansactions? While waiting on queue
2012-02-08 13:22:58,937 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Creating new transaction with name [org.springframework.data.jdbc.jms.listener.oracle.AdtMessageListenerContainer#0]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT>
2012-02-08 13:22:59,000 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Acquired Connection [oracle.jdbc.driver.T4CConnection#9b688e] for JDBC transaction>
2012-02-08 13:22:59,000 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Switching JDBC Connection [oracle.jdbc.driver.T4CConnection#9b688e] to manual commit>
2012-02-08 13:23:00,045 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Initiating transaction commit>
2012-02-08 13:23:00,045 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Committing JDBC transaction on Connection [oracle.jdbc.driver.T4CConnection#9b688e]>
2012-02-08 13:23:00,061 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Releasing JDBC Connection [oracle.jdbc.driver.T4CConnection#9b688e] after transaction>
2012-02-08 13:23:00,061 DEBUG [org.springframework.jdbc.datasource.DataSourceUtils] - <Returning JDBC Connection to DataSource>
2012-02-08 13:23:00,061 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Creating new transaction with name [org.springframework.data.jdbc.jms.listener.oracle.AdtMessageListenerContainer#0]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT>
2012-02-08 13:23:00,093 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Acquired Connection [oracle.jdbc.driver.T4CConnection#eca36e] for JDBC transaction>
2012-02-08 13:23:00,093 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Switching JDBC Connection [oracle.jdbc.driver.T4CConnection#eca36e] to manual commit>
2012-02-08 13:23:01,154 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Initiating transaction commit>
2012-02-08 13:23:01,154 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Committing JDBC transaction on Connection [oracle.jdbc.driver.T4CConnection#eca36e]>
2012-02-08 13:23:01,155 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Releasing JDBC Connection [oracle.jdbc.driver.T4CConnection#eca36e] after transaction>
2012-02-08 13:23:01,155 DEBUG [org.springframework.jdbc.datasource.DataSourceUtils] - <Returning JDBC Connection to DataSource>
2012-02-08 13:23:01,155 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Creating new transaction with name [org.springframework.data.jdbc.jms.listener.oracle.AdtMessageListenerContainer#0]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT>
2012-02-08 13:23:01,202 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Acquired Connection [oracle.jdbc.driver.T4CConnection#19b4748] for JDBC transaction>
2012-02-08 13:23:01,202 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Switching JDBC Connection [oracle.jdbc.driver.T4CConnection#19b4748] to manual commit>
2012-02-08 13:23:02,263 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Initiating transaction commit>
2012-02-08 13:23:02,263 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Committing JDBC transaction on Connection [oracle.jdbc.driver.T4CConnection#19b4748]>
2012-02-08 13:23:02,278 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Releasing JDBC Connection [oracle.jdbc.driver.T4CConnection#19b4748] after transaction>
2012-02-08 13:23:02,278 DEBUG [org.springframework.jdbc.datasource.DataSourceUtils] - <Returning JDBC Connection to DataSource>
2012-02-08 13:23:02,278 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Creating new transaction with name [org.springframework.data.jdbc.jms.listener.oracle.AdtMessageListenerContainer#0]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT>
2012-02-08 13:23:02,311 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Acquired Connection [oracle.jdbc.driver.T4CConnection#1a41cc7] for JDBC transaction>
Below are my spring config
<bean id="dataSource" class="oracle.jdbc.pool.OracleConnectionPoolDataSource">
<property name="URL" value="jdbc:oracle:thin:#//localhost:1521/XE" />
<property name="user" value="migration" />
<property name="password" value="password" />
</bean>
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager"
lazy-init="true">
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="messageDelegate" class="com.test.oracle.aq.ProductDelegate" />
<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">
<jms:listener destination="MIGRATION.PRODUCT_QUEUE" ref="messageDelegate" method="handleMessage" />
</jms:listener-container>
<bean id="messageConverter"
class="org.springframework.data.jdbc.jms.support.converter.oracle.MappingAdtMessageConverter">
<constructor-arg>
<bean class="org.springframework.data.jdbc.jms.support.oracle.StructDatumMapper">
<constructor-arg index="0" value="MIGRATION.PRODUCT_T"/>
<constructor-arg index="1" value="com.test.oracle.aq.Product"/>
</bean>
</constructor-arg>
</bean>
<orcl:aq-jms-connection-factory id="connectionFactory" data-source="dataSource"/>
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="connectionFactory" />
<property name="sessionTransacted" value="true"/>
</bean>
I am having trouble setting up a MDP in Spring 3.0.4 in WebSphere 7.0 using the WebSphereUowTransactionManager.
If I don't use WebSphereUowTransactionManager, it works just fine. Without it, I won't have any XA-action on errors, so I think I really need that.
Here is what happens on the server:
[9/22/10 16:26:35:093 CDT] 00000070 SystemOut O 16:26:35.093 [WorkManager.DefaultWorkManager : 4] DEBUG o.s.t.j.WebSphereUowTransactionManager - Creating new transaction with name [jmsContainer]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT
[9/22/10 16:26:36:140 CDT] 00000070 SystemOut O 16:26:36.140 [WorkManager.DefaultWorkManager : 4] DEBUG o.s.j.l.DefaultMessageListenerContainer - Initiating transaction rollback on listener exception
java.lang.NullPointerException: null
at org.springframework.jms.listener.AbstractMessageListenerContainer.commitIfNecessary(AbstractMessageListenerContainer.java:571) ~[org.springframework.jms-3.0.4.RELEASE.jar:3.0.4.RELEASE]
at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.doReceiveAndExecute(AbstractPollingMessageListenerContainer.java:354) ~[org.springframework.jms-3.0.4.RELEASE.jar:3.0.4.RELEASE]
at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.receiveAndExecute(AbstractPollingMessageListenerContainer.java:241) ~[org.springframework.jms-3.0.4.RELEASE.jar:3.0.4.RELEASE]
at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerContainer.java:1056) [org.springframework.jms-3.0.4.RELEASE.jar:3.0.4.RELEASE]
at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:952) [org.springframework.jms-3.0.4.RELEASE.jar:3.0.4.RELEASE]
at org.springframework.scheduling.commonj.DelegatingWork.run(DelegatingWork.java:61) [org.springframework.context.support-3.0.4.RELEASE.jar:3.0.4.RELEASE]
at com.ibm.ws.asynchbeans.J2EEContext.run(J2EEContext.java:1150) [com.ibm.ws.runtime.jar:na]
at com.ibm.ws.asynchbeans.WorkWithExecutionContextImpl.go(WorkWithExecutionContextImpl.java:199) [com.ibm.ws.runtime.jar:na]
at com.ibm.ws.asynchbeans.CJWorkItemImpl.run(CJWorkItemImpl.java:188) [com.ibm.ws.runtime.jar:na]
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1550) [com.ibm.ws.runtime.jar:na]
[9/22/10 16:26:36:140 CDT] 00000070 SystemOut O 16:26:36.140 [WorkManager.DefaultWorkManager : 4] DEBUG o.s.t.j.WebSphereUowTransactionManager - Initiating transaction rollback
[9/22/10 16:26:41:140 CDT] 00000070 SystemOut O 16:26:41.140 [WorkManager.DefaultWorkManager : 4] WARN o.s.j.l.DefaultMessageListenerContainer - Setup of JMS message listener invoker failed for destination 'queue://testQ?busName=WorkManagementBus' - trying to recover. Cause: null
java.lang.NullPointerException: null
at org.springframework.jms.listener.AbstractMessageListenerContainer.commitIfNecessary(AbstractMessageListenerContainer.java:571) ~[org.springframework.jms-3.0.4.RELEASE.jar:3.0.4.RELEASE]
at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.doReceiveAndExecute(AbstractPollingMessageListenerContainer.java:354) ~[org.springframework.jms-3.0.4.RELEASE.jar:3.0.4.RELEASE]
at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.receiveAndExecute(AbstractPollingMessageListenerContainer.java:241) ~[org.springframework.jms-3.0.4.RELEASE.jar:3.0.4.RELEASE]
at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerContainer.java:1056) ~[org.springframework.jms-3.0.4.RELEASE.jar:3.0.4.RELEASE]
at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:952) ~[org.springframework.jms-3.0.4.RELEASE.jar:3.0.4.RELEASE]
at org.springframework.scheduling.commonj.DelegatingWork.run(DelegatingWork.java:61) [org.springframework.context.support-3.0.4.RELEASE.jar:3.0.4.RELEASE]
at com.ibm.ws.asynchbeans.J2EEContext.run(J2EEContext.java:1150) [com.ibm.ws.runtime.jar:na]
at com.ibm.ws.asynchbeans.WorkWithExecutionContextImpl.go(WorkWithExecutionContextImpl.java:199) [com.ibm.ws.runtime.jar:na]
at com.ibm.ws.asynchbeans.CJWorkItemImpl.run(CJWorkItemImpl.java:188) [com.ibm.ws.runtime.jar:na]
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1550) [com.ibm.ws.runtime.jar:na]
[9/22/10 16:26:41:140 CDT] 00000070 SystemOut O 16:26:41.140 [WorkManager.DefaultWorkManager : 4] INFO o.s.j.l.DefaultMessageListenerContainer - Successfully refreshed JMS Connection
Here is my applicationContext.xml file:
<bean id="transactionManager" class="org.springframework.transaction.jta.WebSphereUowTransactionManager" />
<bean id="myTaskExecutor" class="org.springframework.scheduling.commonj.WorkManagerTaskExecutor">
<property name="workManagerName" value="wm/default" />
</bean>
<jee:jndi-lookup id="queue" jndi-name="jms/queue" resource-ref="true" proxy-interface="javax.jms.Queue"></jee:jndi-lookup>
<jee:jndi-lookup id="connectionFactory" jndi-name="jms/ConnectionFactory" resource-ref="true"></jee:jndi-lookup>
<bean id="jmsContainer"
class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="connectionFactory" ref="connectionFactory"></property>
<property name="destination" ref="queue"></property>
<property name="messageListener" ref="testMessageListener"></property>
<property name="taskExecutor" ref="myTaskExecutor"></property>
<property name="transactionManager" ref="transactionManager"></property>
</bean>
<bean id="testMessageListener" class="navy.jmsey.TestMessageListener" />
I can't figure out why this isn't working. I think I'm doing everything I'm supposed to. I followed the directions in http://www.ibm.com/developerworks/websphere/techjournal/0609_alcott/0609_alcott.html.
Anyone seen this or see what I'm doing wrong?
Thanks.
Update:
I've tried doing a EJB3 Message-driven Bean and that works as expected, on exception it gets redelivered up to 5 times. The problem with that, is the semantics for dependency injection and transaction containment just got more complicated. I'm pretty sure this isn't how I want to go.
Update:
I asked WebSphere support, but they turned me away. As expected.
It seems there is a JIRA on this here.
The person says she managed to get it working by replacing
commitIfNecessary(session, message); // line 354
with
commitIfNecessary(sessionToUse, message);
in the AbstractMessageListenerContainer.java class.