BATCH-1759: re-instate clear() in HibernateItemWriter
This commit is contained in:
@@ -29,7 +29,8 @@ import org.springframework.util.Assert;
|
||||
/**
|
||||
* {@link ItemWriter} that uses a Hibernate session to save or update entities
|
||||
* that are not part of the current Hibernate session. It will also flush the
|
||||
* session at chunk boundaries.<br/>
|
||||
* session at chunk boundaries. It will also flush and clear the session at
|
||||
* chunk boundaries by default (@see ).<br/>
|
||||
* <br/>
|
||||
*
|
||||
* The writer is thread safe after its properties are set (normal singleton
|
||||
@@ -45,6 +46,18 @@ public class HibernateItemWriter<T> implements ItemWriter<T>, InitializingBean {
|
||||
|
||||
private HibernateOperations hibernateTemplate;
|
||||
|
||||
private boolean clearSession = true;
|
||||
|
||||
/**
|
||||
* Flag to indicate that the session should be cleared and flushed at the
|
||||
* end of the write (default true).
|
||||
*
|
||||
* @param clearSession the flag value to set
|
||||
*/
|
||||
public void setClearSession(boolean clearSession) {
|
||||
this.clearSession = clearSession;
|
||||
}
|
||||
|
||||
/**
|
||||
* Public setter for the {@link HibernateOperations} property.
|
||||
*
|
||||
@@ -80,6 +93,9 @@ public class HibernateItemWriter<T> implements ItemWriter<T>, InitializingBean {
|
||||
public final void write(List<? extends T> items) {
|
||||
doWrite(hibernateTemplate, items);
|
||||
hibernateTemplate.flush();
|
||||
if (clearSession) {
|
||||
hibernateTemplate.clear();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user