Announcement Announcement Module
Collapse
No announcement yet.
XAResource working outside transaction Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • XAResource working outside transaction

    I've got to be missing something easy here...

    I am using a JTA transaction manager (the implementation for websphere). It is being used for the both my job repository and is injected into my step. My job is still under construction and has one step. The step consists of:

    a hibernate cursor item reader to read an object graph - a parent entity with many child entities which are being fetched eagerly.
    - I'm setting the HQL query string
    - "useStatelessSession"="false"

    an item processor that takes the object being returned from the reader, and builds a string of XML (which eventually will get sent to a JMSWriter).

    currently my writer does nothing.

    Problem is, during the execution of the processor, when I attempt to access the child entities from the parent, I get the following exception. I figured I have to be missing something. Any suggestions?

    Code:
    2010-10-13 19:42:49:252 [SimpleAsyncTaskExecutor-1] DEBUG org.hibernate.util.JDBCExceptionReporter  - could not initialize a collection: [***]{***}] [****]
    java.sql.SQLException: enlist: caught Exception
    	at com.ibm.ws.rsadapter.AdapterUtil.toSQLException(AdapterUtil.java:1375)
    	at com.ibm.ws.rsadapter.jdbc.WSJdbcConnection.beginTransactionIfNecessary(WSJdbcConnection.java:700)
    	at com.ibm.ws.rsadapter.jdbc.WSJdbcConnection.prepareStatement(WSJdbcConnection.java:2083)
    	at com.ibm.ws.rsadapter.jdbc.WSJdbcConnection.prepareStatement(WSJdbcConnection.java:2038)
    	at ***.datasource.DebugConnection.prepareStatement(DebugConnection.java:62)
    	at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:534)
    	at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:452)
    	at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:161)
    	at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1577)
    	at org.hibernate.loader.Loader.doQuery(Loader.java:696)
    	at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
    	at org.hibernate.loader.Loader.loadCollection(Loader.java:2019)
    	at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:59)
    	at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:587)
    	at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:83)
    	at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1744)
    	at org.hibernate.collection.AbstractPersistentCollection.forceInitialization(AbstractPersistentCollection.java:476)
    	at org.hibernate.engine.StatefulPersistenceContext.initializeNonLazyCollections(StatefulPersistenceContext.java:867)
    	at org.hibernate.loader.Loader.loadSingleRow(Loader.java:317)
    	at org.hibernate.impl.ScrollableResultsImpl.prepareCurrentRow(ScrollableResultsImpl.java:254)
    	at org.hibernate.impl.ScrollableResultsImpl.next(ScrollableResultsImpl.java:123)
    	at org.springframework.batch.item.database.HibernateCursorItemReader.doRead(HibernateCursorItemReader.java:154)
    	at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.read(AbstractItemCountingItemStreamItemReader.java:85)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:79)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.lang.reflect.Method.invoke(Method.java:618)
    	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
    	at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:131)
    	at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:119)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
    	at $Proxy20.read(Unknown Source)
    	at org.springframework.batch.core.step.item.SimpleChunkProvider.doRead(SimpleChunkProvider.java:90)
    	at org.springframework.batch.core.step.item.FaultTolerantChunkProvider.read(FaultTolerantChunkProvider.java:87)
    	at org.springframework.batch.core.step.item.SimpleChunkProvider$1.doInIteration(SimpleChunkProvider.java:108)
    	at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:367)
    	at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:214)
    	at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:143)
    	at org.springframework.batch.core.step.item.SimpleChunkProvider.provide(SimpleChunkProvider.java:103)
    	at org.springframework.batch.core.step.item.ChunkOrientedTasklet.execute(ChunkOrientedTasklet.java:68)
    	at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:360)
    	at org.springframework.transaction.jta.WebSphereUowTransactionManager$UOWActionAdapter.run(WebSphereUowTransactionManager.java:306)
    	at com.ibm.ws.uow.UOWManagerImpl.runUnderNewUOW(UOWManagerImpl.java:948)
    	at com.ibm.ws.uow.UOWManagerImpl.runUnderUOW(UOWManagerImpl.java:509)
    	at org.springframework.transaction.jta.WebSphereUowTransactionManager.execute(WebSphereUowTransactionManager.java:252)
    	at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:122)
    	at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:262)
    	at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:76)
    	at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:367)
    	at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:214)
    	at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:143)
    	at org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:248)
    	at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:195)
    	at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:135)
    	at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:61)
    	at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:60)
    	at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:144)
    	at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:124)
    	at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:135)
    	at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:281)
    	at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:120)
    	at java.lang.Thread.run(Thread.java:810)
    Caused by: javax.resource.ResourceException: enlist: caught Exception
    	at com.ibm.ejs.j2c.XATransactionWrapper.enlist(XATransactionWrapper.java:794)
    	at com.ibm.ejs.j2c.ConnectionManager.lazyEnlist(ConnectionManager.java:1909)
    	at com.ibm.ws.rsadapter.spi.WSRdbManagedConnectionImpl.lazyEnlist(WSRdbManagedConnectionImpl.java:2219)
    	at com.ibm.ws.rsadapter.jdbc.WSJdbcConnection.beginTransactionIfNecessary(WSJdbcConnection.java:643)
    	... 63 more
    Caused by: javax.transaction.RollbackException: XAResource working outside transaction
    	at com.ibm.ws.Transaction.JTA.RegisteredResources.startRes(RegisteredResources.java:1257)
    	at com.ibm.ws.Transaction.JTA.RegisteredResources.enlistResource(RegisteredResources.java:648)
    	at com.ibm.ws.Transaction.JTA.TransactionImpl.enlistResource(TransactionImpl.java:3294)
    	at com.ibm.ws.Transaction.JTA.TranManagerSet.enlist(TranManagerSet.java:405)
    	at com.ibm.ejs.j2c.XATransactionWrapper.enlist(XATransactionWrapper.java:693)
    	... 66 more
    Caused by: com.ibm.db2.jcc.b.qo: [jcc][t4][10401][12066][3.53.95] XA exception: XAER_OUTSIDE ERRORCODE=-4228, SQLSTATE=null
    	at com.ibm.db2.jcc.b.bd.c(bd.java:453)
    	at com.ibm.db2.jcc.b.bd.c(bd.java:477)
    	at com.ibm.db2.jcc.t4.ac.a(ac.java:1730)
    	at com.ibm.db2.jcc.t4.ac.start(ac.java:1597)
    	at com.ibm.ws.rsadapter.spi.WSRdbXaResourceImpl.start(WSRdbXaResourceImpl.java:1417)
    	at com.ibm.ejs.j2c.XATransactionWrapper.start(XATransactionWrapper.java:1467)
    	at com.ibm.ws.Transaction.JTA.JTAResourceBase.start(JTAResourceBase.java:145)
    	at com.ibm.ws.Transaction.JTA.RegisteredResources.startRes(RegisteredResources.java:1240)

  • #2
    I worked around this by basically reading keys in the reader, then fetching additional data in the process step before building my xml...

    All is well. I suppose the theme is that the intent of the reader is to collect/iterate through parents, then retrieve additional data later.

    Comment

    Working...
    X