Class HibernateItemWriter<T>
java.lang.Object
org.springframework.batch.item.database.HibernateItemWriter<T>
- All Implemented Interfaces:
ItemWriter<T>
,org.springframework.beans.factory.InitializingBean
public class HibernateItemWriter<T>
extends 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).The writer is thread-safe once properties are set (normal singleton behavior) if a
CurrentSessionContext
that uses only one session per thread is
used.- Author:
- Dave Syer, Thomas Risberg, Michael Minella, Mahmoud Ben Hassine
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Check mandatory properties - there must be a sessionFactory.protected void
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
Save or update any entities not in the current hibernate session and then flush the hibernate session.
-
Field Details
-
logger
protected static final org.apache.commons.logging.Log logger
-
-
Constructor Details
-
HibernateItemWriter
public HibernateItemWriter()
-
-
Method Details
-
setClearSession
public void setClearSession(boolean clearSession) Flag to indicate that the session should be cleared and flushed at the end of the write (default true).- Parameters:
clearSession
- the flag value to set
-
setSessionFactory
public void setSessionFactory(org.hibernate.SessionFactory sessionFactory) Set the Hibernate SessionFactory to be used internally.- Parameters:
sessionFactory
- session factory to be used by the writer
-
afterPropertiesSet
public void afterPropertiesSet()Check mandatory properties - there must be a sessionFactory.- Specified by:
afterPropertiesSet
in interfaceorg.springframework.beans.factory.InitializingBean
-
write
Save or update any entities not in the current hibernate session and then flush the hibernate session.- Specified by:
write
in interfaceItemWriter<T>
- Parameters:
items
- items to be written- See Also:
-
doWrite
Do perform the actual write operation using Hibernate's API. This can be overridden in a subclass if necessary.- Parameters:
sessionFactory
- Hibernate SessionFactory to be useditems
- the list of items to use for the write
-