Interface HibernateOperations

All Known Implementing Classes:

public interface HibernateOperations
Interface that specifies a common set of Hibernate operations as well as a general execute(org.springframework.orm.hibernate5.HibernateCallback<T>) method for Session-based lambda expressions. Implemented by HibernateTemplate. Not often used, but a useful option to enhance testability, as it can easily be mocked or stubbed.

Defines HibernateTemplate's data access methods that mirror various Session methods. Users are strongly encouraged to read the Hibernate Session javadocs for details on the semantics of those methods.

A deprecation note: While HibernateTemplate and this operations interface are being kept around for backwards compatibility in terms of the data access implementation style in Spring applications, we strongly recommend the use of native Session access code for non-trivial interactions. This in particular affects parameterized queries where - on Java 8+ - a custom HibernateCallback lambda code block with createQuery and several setParameter calls on the Query interface is an elegant solution, to be executed via the general execute(org.springframework.orm.hibernate5.HibernateCallback<T>) method. All such operations which benefit from a lambda variant have been marked as deprecated on this interface.

A Hibernate compatibility note: HibernateTemplate and the operations on this interface generally aim to be applicable across all Hibernate versions. In terms of binary compatibility, Spring ships a variant for each major generation of Hibernate (in the present case: Hibernate ORM 5.x). However, due to refactorings and removals in Hibernate ORM 5.3, some variants - in particular legacy positional parameters starting from index 0 - do not work anymore. All affected operations are marked as deprecated; please replace them with the general execute(org.springframework.orm.hibernate5.HibernateCallback<T>) method and custom lambda blocks creating the queries, ideally setting named parameters through Query. Please be aware that deprecated operations are known to work with Hibernate ORM 5.2 but may not work with Hibernate ORM 5.3 and higher anymore.

Juergen Hoeller
See Also: