public class HibernateItemWriter<T> extends java.lang.Object implements ItemWriter<T>, org.springframework.beans.factory.InitializingBean
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 after writing (i.e. at chunk boundaries if used in a Spring Batch
TaskletStep). It will also clear the session on write
default (see clearSession
property).CurrentSessionContext
that uses only one session per thread is
used.Modifier and Type | Field and Description |
---|---|
protected static org.apache.commons.logging.Log |
logger |
Constructor and Description |
---|
HibernateItemWriter() |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet()
Check mandatory properties - there must be a sessionFactory.
|
protected void |
doWrite(org.springframework.orm.hibernate5.HibernateOperations hibernateTemplate,
java.util.List<? extends T> items)
Deprecated.
As of 2.2 in favor of using Hibernate's session management APIs directly
|
protected void |
doWrite(org.hibernate.SessionFactory sessionFactory,
java.util.List<? extends T> items)
Do perform the actual write operation using Hibernate's API.
|
void |
setClearSession(boolean clearSession)
Flag to indicate that the session should be cleared and flushed at the
end of the write (default true).
|
void |
setSessionFactory(org.hibernate.SessionFactory sessionFactory)
Set the Hibernate SessionFactory to be used internally.
|
void |
write(java.util.List<? extends T> items)
Save or update any entities not in the current hibernate session and then
flush the hibernate session.
|
public void setClearSession(boolean clearSession)
clearSession
- the flag value to setpublic void setSessionFactory(org.hibernate.SessionFactory sessionFactory)
sessionFactory
- session factory to be used by the writerpublic void afterPropertiesSet()
afterPropertiesSet
in interface org.springframework.beans.factory.InitializingBean
public void write(java.util.List<? extends T> items)
write
in interface ItemWriter<T>
items
- items to be writtenItemWriter.write(java.util.List)
protected void doWrite(org.hibernate.SessionFactory sessionFactory, java.util.List<? extends T> items)
sessionFactory
- Hibernate SessionFactory to be useditems
- the list of items to use for the write@Deprecated protected void doWrite(org.springframework.orm.hibernate5.HibernateOperations hibernateTemplate, java.util.List<? extends T> items)
HibernateOperations
.
This can be overridden in a subclass if necessary.hibernateTemplate
- the HibernateTemplate to use for the operationitems
- the list of items to use for the write