Transactional rollBack if something goes wrong in the internal database.
Hi,
I splitted the datasource for the Business object from the datasource used by Spring Batch. And my problem is that if I cause a runtime exception while the database job data is inserted (like a DAtaIntegrityViolation changing a column type in the BATCH_STEP_EXECUTION table) then the rollback on the JOB_EXECUTION table is not done... I would expect all the data inserted regarding the job to be removed from the database.
I'm using Hibernate for my domain and I defined a session factory for my object:
org.springframework.orm.hibernate3.annotation.Anno tationSessionFactoryBean
referred by a:
org.springframework.orm.hibernate3.HibernateTransa ctionManager
then I have another transaction manager:
org.springframework.jdbc.datasource.DataSourceTran sactionManager
referring to the batch data source.
I configured this advice:
<bean id="jobRepository"
class="org.springframework.batch.core.repository.s upport.JobRepositoryFactoryBean"
p:databaseType="mysql" p:dataSource-ref="batchDataSource" />
<aop:config>
<aop:advisor
pointcut="execution(* org.springframework.batch.core..*Repository+.*(..) )"
advice-ref="txAdvice" />
</aop:config>
<tx:advice id="txAdvice"
transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="*" propagation="REQUIRED_NEW"
isolation="SERIALIZABLE" read-only="false" />
<tx:method name="*" />
</tx:attributes>
</tx:advice>
as seen in the sample; only changing the method name to * because actually my exception arises when the method:
public void saveOrUpdate(StepExecution stepExecution)
is called in the SimpleJobRepository.
But what happen is that the exception is thrown when trying to insert the step_execution data but the row in the job_execution table remains. I also tried changing REQUIRED_NEW to REQUIRE but without any success. Any glue or suggestion on it? Is it because I'm not using a JtaTransactionManager?
I need to be sure that neither the internal database used by Spring batch doesn't risk to be missed up if a runtime exception arise when persisting the job repository data.
Thanks in advance,
Vicio.