Results 1 to 4 of 4

Thread: Transaction Manager - Hibernate + OutputXML

  1. #1
    Join Date
    Feb 2011
    Posts
    6

    Question Transaction Manager - Hibernate + OutputXML

    Hello,

    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" />
    </bean>

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

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


    My job main lines are:

    <bean id="myJob" class="org.springframework.batch.core.job.SimpleJo b">
    <property name="jobRepository" ref="jobRepository" />
    <property name="steps">
    <list>
    <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>
    <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>
    </list>
    </property>
    </bean>

    <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" />

    </bean>


    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 - org.springframework.transaction.support.Transactio nSynchronizationUtils.invokeAfterCompletion(Transa ctionSynchronizationUtils.java:160)TransactionSync hronization.afterCompletion threw exception
    org.springframework.batch.support.transaction.Flus hFailedException: Could not write to output buffer
    at org.springframework.batch.support.transaction.Tran sactionAwareBufferedWriter$1.afterCompletion(Trans actionAwareBufferedWriter.java:71)
    at org.springframework.transaction.support.Transactio nSynchronizationUtils.invokeAfterCompletion(Transa ctionSynchronizationUtils.java:157)
    at org.springframework.transaction.support.AbstractPl atformTransactionManager.invokeAfterCompletion(Abs tractPlatformTransactionManager.java:974)
    at org.springframework.transaction.support.AbstractPl atformTransactionManager.triggerAfterCompletion(Ab stractPlatformTransactionManager.java:949)
    at org.springframework.transaction.support.AbstractPl atformTransactionManager.processCommit(AbstractPla tformTransactionManager.java:777)
    at org.springframework.transaction.support.AbstractPl atformTransactionManager.commit(AbstractPlatformTr ansactionManager.java:701)
    at org.springframework.transaction.interceptor.Transa ctionAspectSupport.commitTransactionAfterReturning (TransactionAspectSupport.java:321)
    at org.springframework.transaction.interceptor.Transa ctionInterceptor.invoke(TransactionInterceptor.jav a:116)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :171)
    at org.springframework.aop.interceptor.ExposeInvocati onInterceptor.invoke(ExposeInvocationInterceptor.j ava:89)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :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(BatchMainLauncher.java:126)
    Caused by: java.io.IOException: Controlador no válido
    at java.io.FileOutputStream.writeBytes(Native Method)
    at java.io.FileOutputStream.write(Unknown 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 java.io.OutputStreamWriter.flush(Unknown Source)
    at org.springframework.batch.support.transaction.Tran sactionAwareBufferedWriter$1.afterCompletion(Trans actionAwareBufferedWriter.java:68)
    ... 13 more


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

    Thanks!!

  2. #2
    Join Date
    Dec 2005
    Location
    Lyon, France
    Posts
    311

    Default

    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. #3
    Join Date
    Feb 2011
    Posts
    6

    Default

    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. #4
    Join Date
    Dec 2005
    Location
    Lyon, France
    Posts
    311

    Default

    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.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •