319878 (4) [Avatar] Offline
#1
Hi,
I want to use ResourcelessTransactionManager as transactionManager for jobRepository:
    <!-- MapJobRepositoryFactoryBean uses ResourcelessTransactionManager -->
    <bean id="jobRepository"
          class="org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean">
    </bean>


but my writer writes to a persistent database "Oracle" so I have a separate transaction manager for that:

@Bean
public DataSourceTransactionManager transactionManager() {
    return new DataSourceTransactionManager(dataSource());
}

Now when I define a job then it should use "transactionManager" bean (by default).

I don't need to persist job metadata and hence I am using MapJobRepositoryFactoryBean. Is this a correct configuration where job metadata is using different transaction manager (ResourcelessTransactionManager) and job is using different transaction manager?

(I don't want to use global transaction manager and I cannot store job metadata tables in my persistent database)

Thanks,
Ashish
arnaud.cogoluegnes (73) [Avatar] Offline
#2
Hi,

This is more related to Spring Batch itself than to the book, so you'd better off asking on the Spring Batch forum (http://stackoverflow.com/questions/tagged/spring-batch) Nevertheless I can help a little.

I don't know your use case exactly, but you can use explicit dependency injection in the JobRepository or at the tasklet level, or on any other bean. So you could inject your DataSourceTransactionManager explicitly wherever you want. If you let Spring Batch drive the transactions in an chunk-oriented step, you should inject the DataSourceTransactionManager at the tasklet level.

Regards,

Arnaud
319878 (4) [Avatar] Offline
#3
Thanks Arnaud.
I did post to that before posting here:
http://stackoverflow.com/questions/31550818/spring-batch-use-of-resourcelesstransactionmanager-as-transactionmanager-for-jo

Basically I want to use ResourcelessTransactionManager as transactionManager for jobRepository and at the same time I want to use DataSourceTransactionManager at the tasklet level so that Spring batch manages the transaction (in a chunk-oriented step). When i do that it works fine but I am just wondering if this is correct ?

Regards,
Ashish
arnaud.cogoluegnes (73) [Avatar] Offline
#4
Yes, it should work fine: the Tasklet should be able to demarcate the transactions for the chunk-oriented processing. But you'll loose monitoring and restartability because you're not using the persistent job repository. It looks like you're ok with that.
319878 (4) [Avatar] Offline
#5
Thanks Arnaud. Yes I am fine with it even if there is no restart or monitoring capability.

Just to give you some idea, this job works as follows - it tries to insert in a database and in case of database outage it stores the message in a Queue. I can't store JobRepository tables in the same database otherwise it will cause job to fail in case if database is down. (Database outage is expected and job should succeed even if there is an database outage)

Regards,
Ashish
319878 (4) [Avatar] Offline
#6
Hi Arnaud, I must add that I truly enjoyed reading 'Spring Batch in Action" book. Spring batch seems to be a very powerful tool. I am able to model most of the requirements to batch jobs and it's so easy to read and write data and at the same time I get robustness and reliability (skipping, retry etc.). Job monitoring is also very convenient using SpringBatchAdmin.
Thanks a lot for explaining Spring batch concepts in such a nice way smilie

Regards,
Ashish