Issue Details (XML | Word | Printable)

Key: BATCH-237
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Dave Syer
Reporter: Robert Kasanicky
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Spring Batch

HibernateAwareItemWriter should clear session after flushing

Created: 29/Nov/07 09:52 AM   Updated: 07/Aug/08 10:06 AM
Component/s: Infrastructure
Affects Version/s: 1.0-m3
Fix Version/s: 1.0-m3
Security Level: Public (Public Issues)

Time Tracking:
Original Estimate: 0.12d
Original Estimate - 0.12d
Remaining Estimate: 0d
Time Spent - 0.12d
Time Spent: 0.12d
Time Spent - 0.12d


 Description  « Hide
After changes have been flushed to database session cache should be cleared.

The code update itself is trivial, but tests need to be updated too. Adding the clear() call breaks current tests because they use a hacked test version of HibernateTemplate. Also the updated tests should check that the clear() method has been called as expected.

 All   Comments   Work Log   Change History   FishEye   Builds      Sort Order: Ascending order - Click to sort in descending order
Dave Syer added a comment - 29/Nov/07 11:56 AM
Won't the session be cleared automatically by the transaction ends? When we flush, we expect a transaction boundary to be imminent (we are only flushing eagerly to fit the flush inside the repeat template remember).

Robert Kasanicky added a comment - 30/Nov/07 03:20 AM
As far as I am aware there is no automatic session clearing (but maybe this is primarily a matter of wording). It is just a typical usecase that a session lifetime matches a single transaction, but it is also perfectly valid scenario that a single session spans multiple transactions. From the point of view of HibernateAwareItemWriter I can't see any guarantee it would deal with a fresh session when a new transaction starts, so I think it should clear the session explicitly.

Dave Syer added a comment - 30/Nov/07 03:58 AM
Apparently the HibernateTransactionManager will close() the session (which naturally clears it). It is safe to assume that a Spring Batch client is using Spring TX management, so I think it is also safe to assume that the session will be cleared at the end of a chunk no matter what.

Thanks for taking the time to think about this though.

Dave Syer added a comment - 30/Nov/07 07:57 AM
Added clear() after flush (and test case)

Dave Syer added a comment - 07/Aug/08 10:06 AM
Assume closed as resolved and released