Top Description Fields Constructors Methods
org.springframework.orm.hibernate5

public Class SpringSessionSynchronization

extends Object
implements TransactionSynchronization, Ordered
Class Inheritance
All Implemented Interfaces
org.springframework.core.Ordered, org.springframework.transaction.support.TransactionSynchronization, java.io.Flushable
Imports
org.hibernate.FlushMode, .Session, .SessionFactory, org.hibernate.engine.spi.SessionImplementor, org.springframework.core.Ordered, org.springframework.dao.DataAccessException, org.springframework.transaction.support.TransactionSynchronization, .TransactionSynchronizationManager

Callback for resource cleanup at the end of a Spring-managed transaction for a pre-bound Hibernate Session.
Author
Juergen Hoeller
Since
4.2

Field Summary

Modifier and TypeField and Description
private boolean
private final boolean
private final SessionFactory
sessionFactory

References Deprecated SessionFactory is deprecated or references (maybe indirectly) at least one deprecated element.
private final SessionHolder

Constructor Summary

AccessConstructor and Description
public
SpringSessionSynchronization(SessionHolder sessionHolder, SessionFactory sessionFactory)
References Deprecated SessionFactory is deprecated or references (maybe indirectly) at least one deprecated element.

public
SpringSessionSynchronization(SessionHolder sessionHolder, SessionFactory sessionFactory, boolean newSession)
References Deprecated SessionFactory is deprecated or references (maybe indirectly) at least one deprecated element.

Method Summary

Modifier and TypeMethod and Description
public void
public void
afterCompletion(int
completion status according to the STATUS_* constants
status
)

Overrides default org.springframework.transaction.support.TransactionSynchronization.afterCompletion.

Invoked after transaction commit/rollback.

public void
beforeCommit(boolean
whether the transaction is defined as read-only transaction
readOnly
)

Overrides default org.springframework.transaction.support.TransactionSynchronization.beforeCommit.

Invoked before transaction commit (before "beforeCompletion").

public void
beforeCompletion()

Overrides default org.springframework.transaction.support.TransactionSynchronization.beforeCompletion.

Invoked before transaction commit/rollback.

public void
flush()

Overrides default org.springframework.transaction.support.TransactionSynchronization.flush.

Flush the underlying session to the datastore, if applicable: for example, a Hibernate/JPA session.

private Session
getCurrentSession()
References Deprecated Session is deprecated or references (maybe indirectly) at least one deprecated element.

public int
getOrder()

Overrides default org.springframework.transaction.support.TransactionSynchronization.getOrder.

Implements org.springframework.core.Ordered.getOrder.

Return the execution order for this transaction synchronization.

public void
public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

holderActiveback to summary
private boolean holderActive
newSessionback to summary
private final boolean newSession
sessionFactoryback to summary
private final SessionFactory sessionFactory

References Deprecated

SessionFactory is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

sessionHolderback to summary
private final SessionHolder sessionHolder

Constructor Detail

SpringSessionSynchronizationback to summary
public SpringSessionSynchronization(SessionHolder sessionHolder, SessionFactory sessionFactory)

References Deprecated

SessionFactory is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

SpringSessionSynchronizationback to summary
public SpringSessionSynchronization(SessionHolder sessionHolder, SessionFactory sessionFactory, boolean newSession)

References Deprecated

SessionFactory is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Method Detail

afterCommitback to summary
public void afterCommit()

Overrides default org.springframework.transaction.support.TransactionSynchronization.afterCommit.

Doc from org.springframework.transaction.support.TransactionSynchronization.afterCommit.

Invoked after transaction commit. Can perform further operations right after the main transaction has successfully committed.

Can e.g. commit further operations that are supposed to follow on a successful commit of the main transaction, like confirmation messages or emails.

Note

The transaction will have been committed already, but the transactional resources might still be active and accessible. As a consequence, any data access code triggered at this point will still "participate" in the original transaction, allowing to perform some cleanup (with no commit following anymore!), unless it explicitly declares that it needs to run in a separate transaction. Hence: Use PROPAGATION_REQUIRES_NEW for any transactional operation that is called from here.

Annotations
@Override
afterCompletionback to summary
public void afterCompletion(int status)

Overrides default org.springframework.transaction.support.TransactionSynchronization.afterCompletion.

Doc from org.springframework.transaction.support.TransactionSynchronization.afterCompletion.

Invoked after transaction commit/rollback. Can perform resource cleanup after transaction completion.

Note

The transaction will have been committed or rolled back already, but the transactional resources might still be active and accessible. As a consequence, any data access code triggered at this point will still "participate" in the original transaction, allowing to perform some cleanup (with no commit following anymore!), unless it explicitly declares that it needs to run in a separate transaction. Hence: Use PROPAGATION_REQUIRES_NEW for any transactional operation that is called from here.

Parameters
status:int

completion status according to the STATUS_* constants

Annotations
@Override
beforeCommitback to summary
public void beforeCommit(boolean readOnly) throws DataAccessException

Overrides default org.springframework.transaction.support.TransactionSynchronization.beforeCommit.

Doc from org.springframework.transaction.support.TransactionSynchronization.beforeCommit.

Invoked before transaction commit (before "beforeCompletion"). Can e.g. flush transactional O/R Mapping sessions to the database.

This callback does not mean that the transaction will actually be committed. A rollback decision can still occur after this method has been called. This callback is rather meant to perform work that's only relevant if a commit still has a chance to happen, such as flushing SQL statements to the database.

Note that exceptions will get propagated to the commit caller and cause a rollback of the transaction.

Parameters
readOnly:boolean

whether the transaction is defined as read-only transaction

Annotations
@Override
beforeCompletionback to summary
public void beforeCompletion()

Overrides default org.springframework.transaction.support.TransactionSynchronization.beforeCompletion.

Doc from org.springframework.transaction.support.TransactionSynchronization.beforeCompletion.

Invoked before transaction commit/rollback. Can perform resource cleanup before transaction completion.

This method will be invoked after beforeCommit, even when beforeCommit threw an exception. This callback allows for closing resources before transaction completion, for any outcome.

Annotations
@Override
flushback to summary
public void flush()

Overrides default org.springframework.transaction.support.TransactionSynchronization.flush.

Doc from org.springframework.transaction.support.TransactionSynchronization.flush.

Flush the underlying session to the datastore, if applicable: for example, a Hibernate/JPA session.

Annotations
@Override
getCurrentSessionback to summary
private Session getCurrentSession()

References Deprecated

Session is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

getOrderback to summary
public int getOrder()

Overrides default org.springframework.transaction.support.TransactionSynchronization.getOrder.

Implements org.springframework.core.Ordered.getOrder.

Doc from org.springframework.transaction.support.TransactionSynchronization.getOrder.

Return the execution order for this transaction synchronization.

Default is Ordered#LOWEST_PRECEDENCE.

Returns:int

Doc from org.springframework.core.Ordered.getOrder.

the order value

Annotations
@Override
resumeback to summary
public void resume()

Overrides default org.springframework.transaction.support.TransactionSynchronization.resume.

Doc from org.springframework.transaction.support.TransactionSynchronization.resume.

Resume this synchronization. Supposed to rebind resources to TransactionSynchronizationManager if managing any.

Annotations
@Override
suspendback to summary
public void suspend()

Overrides default org.springframework.transaction.support.TransactionSynchronization.suspend.

Doc from org.springframework.transaction.support.TransactionSynchronization.suspend.

Suspend this synchronization. Supposed to unbind resources from TransactionSynchronizationManager if managing any.

Annotations
@Override