Noa Drach
Noa Drach

Reputation: 2481

Spring Batch - Connection closed in when processing is done in external process

I tried the following workarounds

Any ideas how I can work around this?

Can I configure a job listener that will restart the job from the step that follows the Pentaho step?

Additional info I think that the issue is here - org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSource)

This

    ConnectionHolder conHolder = (ConnectionHolder) TransactionSynchronizationManager.getResource(dataSource);

thinks that the connection is valid

so I guess the solution will be to call org.springframework.transaction.support.TransactionSynchronizationManager.unbindResource(Object)

and the question is how can I get the data source object to pass to this method

I will try querying the org.springframework.transaction.support.TransactionSynchronizationManager.getResourceMap() and see where it gets me

update no luck - the get resources map gives me just the repositories I'm using, not the data source. Still digging...

Another update

I'm debugging the process and it seems that the problem is indeed org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSource) the connection holder is holding a connection that is closed but the code here doesn't check if the connection is open; it only checks if the connection isn't null and if it was some weak reference maybe it was enough here - but in this use case it just proceedes with the closed connection instead of requesting a new one.

Upvotes: 4

Views: 11444

Answers (1)

Noa Drach
Noa Drach

Reputation: 2481

add this to the tasklet definition

<batch:transaction-attributes propagation="NEVER" />

since the Tasklet is doing external processing and doesn't need a spring batch transaction it need to tell spring batch not to open a transaction for this tasklet.

see http://www.javabeat.net/transaction-management-in-spring-batch-components/ http://forum.spring.io/forum/spring-projects/batch/91158-legacy-integration-tasklet-transaction

Upvotes: 3

Related Questions