public class HibernateSessionManager extends Object
Session. Methods will
throw IllegalStateException if there is no active session on the executing thread.Session,
SessionFactoryUtils.getSession(SessionFactory, boolean)| Constructor and Description |
|---|
HibernateSessionManager(net.sf.hibernate.SessionFactory sessionFactory,
org.springframework.transaction.PlatformTransactionManager transactionManager) |
| Modifier and Type | Method and Description |
|---|---|
void |
evict(Object object)
Removes the object and its dependents from the active session.
|
<I,O> Iterable<O> |
executeWithSessionClearing(Iterable<I> input,
int batchSize,
int expectedTotal,
com.google.common.base.Function<I,O> task)
Executes a bulk database update in a way that prevents excessive memory usage, by committing the
transaction and clearing the session periodically.
|
<I,O> Iterable<O> |
executeWithSessionFlushAndClear(Iterable<I> input,
int batchSize,
int expectedTotal,
com.google.common.base.Function<I,O> task)
Reuses the current transaction, to avoid nested transaction issues.
|
net.sf.hibernate.Session |
getSession()
Returns the current session.
|
public HibernateSessionManager(net.sf.hibernate.SessionFactory sessionFactory,
org.springframework.transaction.PlatformTransactionManager transactionManager)
public net.sf.hibernate.Session getSession()
IllegalStateException - if there is no active sessionpublic void evict(Object object)
This method should be used when processing a large number of Hibernate objects in a read-only fashion.
IllegalStateException - if there is no active sessionorg.springframework.dao.DataAccessException - if there is a problem evicting the objectSession.evict(Object)public <I,O> Iterable<O> executeWithSessionClearing(Iterable<I> input, int batchSize, int expectedTotal, com.google.common.base.Function<I,O> task)
task is executed once per
input item. The commit and session-clearing is done once per batchSize items.
WARNING: the session clearing will discard any unflushed or uncommitted changes made higher in the stack. Batch operations using this method should generally be done in a separate thread or otherwise outside the scope of a request.
I - the type of the input itemsO - the type of the resulting items, which can be Voidinput - the list of items to processtask - the task to executebatchSize - a transaction will be committed and the session will be cleared after this many input itemsexpectedTotal - the total number of items, used for logging. A value of 0 indicates expected total is not known.IllegalStateException - if there is no active sessionorg.springframework.dao.DataAccessException - if there is a problem committing changes to the databaseCopyright © 2003–2016 Atlassian. All rights reserved.