From c022df6ce00aba957a249b1536e755997a5d566f Mon Sep 17 00:00:00 2001 From: dsyer Date: Sat, 22 Dec 2007 09:40:59 +0000 Subject: [PATCH] RESOLVED - issue BATCH-262: Hibernate Job blocks on flush http://jira.springframework.org/browse/BATCH-262 The hibernate job blocks with high isolatio nlevels because it is reading a cursor and then updating the same objects (the cursor is in a different transaction because it uses openSession()). The resolution is to change the isolation level - might be worth some more careful work later to encourage the right sort of best practice. --- .../resources/alt-data-source-context.xml | 4 +- .../main/resources/data-source-context.xml | 52 ++++++++++++------- .../resources/simple-container-definition.xml | 3 +- .../AbstractCustomerCreditIncreaseTests.java | 21 +++++--- 4 files changed, 50 insertions(+), 30 deletions(-) diff --git a/spring-batch-samples/src/main/resources/alt-data-source-context.xml b/spring-batch-samples/src/main/resources/alt-data-source-context.xml index d1cc53ac4..c96b08d55 100644 --- a/spring-batch-samples/src/main/resources/alt-data-source-context.xml +++ b/spring-batch-samples/src/main/resources/alt-data-source-context.xml @@ -11,7 +11,9 @@ - + + - - - + + - + - + - + - + - + - + - + - + - + - + - + - + @@ -61,7 +69,8 @@ - + @@ -69,17 +78,20 @@ - + - - + + - + \ No newline at end of file diff --git a/spring-batch-samples/src/main/resources/simple-container-definition.xml b/spring-batch-samples/src/main/resources/simple-container-definition.xml index ab4ece662..b0a27e1b4 100644 --- a/spring-batch-samples/src/main/resources/simple-container-definition.xml +++ b/spring-batch-samples/src/main/resources/simple-container-definition.xml @@ -40,7 +40,8 @@ - + + diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/AbstractCustomerCreditIncreaseTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/AbstractCustomerCreditIncreaseTests.java index 3a6c9ce19..126f7a23d 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/AbstractCustomerCreditIncreaseTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/AbstractCustomerCreditIncreaseTests.java @@ -75,17 +75,22 @@ public abstract class AbstractCustomerCreditIncreaseTests extends AbstractValida final List matches = new ArrayList(); - jdbcTemplate.query(ALL_CUSTOMERS, new RowMapper() { + new TransactionTemplate(transactionManager).execute(new TransactionCallback() { + public Object doInTransaction(TransactionStatus status) { + jdbcTemplate.query(ALL_CUSTOMERS, new RowMapper() { - public Object mapRow(ResultSet rs, int rowNum) throws SQLException { - final BigDecimal creditBeforeUpdate = (BigDecimal) creditsBeforeUpdate.get(rowNum); - final BigDecimal expectedCredit = creditBeforeUpdate.add(CREDIT_INCREASE); - if (expectedCredit.equals(rs.getBigDecimal(CREDIT_COLUMN))) { - matches.add(rs.getBigDecimal(ID_COLUMN)); - } + public Object mapRow(ResultSet rs, int rowNum) throws SQLException { + final BigDecimal creditBeforeUpdate = (BigDecimal) creditsBeforeUpdate.get(rowNum); + final BigDecimal expectedCredit = creditBeforeUpdate.add(CREDIT_INCREASE); + if (expectedCredit.equals(rs.getBigDecimal(CREDIT_COLUMN))) { + matches.add(rs.getBigDecimal(ID_COLUMN)); + } + return null; + } + + }); return null; } - }); assertEquals(getExpectedMatches(), matches.size());