Announcement Announcement Module
No announcement yet.
Transaction Manager - Hibernate + OutputXML Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Transaction Manager - Hibernate + OutputXML


    I've been working with this issue for more than 3 days. I need a really good hand which can help me solve this!

    Here's the thing:

    In order to launch our Jobs we've created a JobLauncher class. Since this class was created and assigned a transaction-manager, my jobs which read from DB, create an XML and update some records are no longer working.

    these are extracts from the files:

    This is the txManager that was add to the Class which launches our jobs

    <bean id="txManager"
    class="org.springframework.orm.hibernate3.Hibernat eTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />

    <tx:advice id="batchTxAdvice" transaction-manager="txManager">
    <tx:method name="execute*" propagation="REQUIRED"
    rollback-for="JobExecutionException" />

    <aopointcut id="batchMethods"
    expression="execution(*com.outils.execution.BatchL auncher.*(..))" />
    <aop:advisor advice-ref="batchTxAdvice" pointcut-ref="batchMethods" />

    My job main lines are:

    <bean id="myJob" class="org.springframework.batch.core.job.SimpleJo b">
    <property name="jobRepository" ref="jobRepository" />
    <property name="steps">
    <bean id="myStep"
    class="org.springframework.batch.core.step.item.Si mpleStepFactoryBean">
    <property name="jobRepository" ref="jobRepository" />
    <property name="transactionManager" ref="jobTransactionManager" />
    <property name="itemReader" ref="myItemReader" />
    <property name="itemWriter" ref="myItemWriter" />
    <bean id="myUpdateStep"
    class="org.springframework.batch.core.step.item.Si mpleStepFactoryBean">
    <property name="jobRepository" ref="jobRepository" />
    <property name="transactionManager" ref="jobTransactionManager" />
    <property name="itemReader" ref="myRecordsReader" />
    <property name="itemWriter" ref="myRecordsWriter" />

    <bean id="myItemWriter" class="org.springframework.batch.item.xml.StaxEven tItemWriter" >
    <property name="rootTagName" value="mainTag"/>
    <property name="overwriteOutput" value="true"/>
    <property name="resource" ref="myResource" />
    <property name="marshaller" ref=myMarshaller" />


    This used to work ok until the txManager for the batchLauncher was added.
    This is the error I get...

    21/02/11 16:09:11.138 ERROR - nSynchronizationUtils.invokeAfterCompletion(Transa hronization.afterCompletion threw exception hFailedException: Could not write to output buffer
    at sactionAwareBufferedWriter$1.afterCompletion(Trans
    at nSynchronizationUtils.invokeAfterCompletion(Transa
    at atformTransactionManager.invokeAfterCompletion(Abs
    at atformTransactionManager.triggerAfterCompletion(Ab
    at atformTransactionManager.processCommit(AbstractPla
    at atformTransactionManager.commit(AbstractPlatformTr
    at org.springframework.transaction.interceptor.Transa ctionAspectSupport.commitTransactionAfterReturning (
    at org.springframework.transaction.interceptor.Transa ctionInterceptor.invoke(TransactionInterceptor.jav a:116)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed( :171)
    at org.springframework.aop.interceptor.ExposeInvocati onInterceptor.invoke(ExposeInvocationInterceptor.j ava:89)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed( :171)
    at org.springframework.aop.framework.Cglib2AopProxy$D ynamicAdvisedInterceptor.intercept(Cglib2AopProxy. java:635)
    at com.inetpsa.acj.outils.execution.BatchLauncher$$En hancerByCGLIB$$c37c5bdf.execute(<generated>)
    at com.inetpsa.acj.outils.execution.BatchMainLauncher .main(
    Caused by: Controlador no válido
    at Method)
    at Source)
    at sun.nio.cs.StreamEncoder.writeBytes(Unknown Source)
    at sun.nio.cs.StreamEncoder.implFlushBuffer(Unknown Source)
    at sun.nio.cs.StreamEncoder.implFlush(Unknown Source)
    at sun.nio.cs.StreamEncoder.flush(Unknown Source)
    at Source)
    at sactionAwareBufferedWriter$1.afterCompletion(Trans
    ... 13 more

    Since I'm pretty new with this framework any help would be much appreciated!!


  • #2
    quite hard to figure out where the problem is. Perhaps you should try with Spring Batch's SimpleJobLauncher if you meet the same problem. Check also that you can write the file you want to write to (the error looks like to happen when flushing the stream on the transaction commit.)

    btw, why do you need a custom, transactional job launcher?


    • #3
      Actually the BatchLauncher calls the SimpleJobLauncher. I can write the file without any problem as long as I remove the pointcut.
      I do not need a custom transactional job launcher in my case, but since this job is part of a bigger project where there are others jobs that really need that, we've created this transaction at a job level.


      • #4
        I don't think that Spring Batch can work properly this way. The framework handles transactions itself, at the step level. Perhaps you should think about re-designing your jobs in one job and letting Spring Batch dealing with transactions.