@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
/ *
* Copyright 2002 - 2015 the original author or authors .
* Copyright 2002 - 2018 the original author or authors .
*
* Licensed under the Apache License , Version 2 . 0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
@ -30,14 +30,37 @@ import org.springframework.dao.DataAccessException;
@@ -30,14 +30,37 @@ import org.springframework.dao.DataAccessException;
import org.springframework.lang.Nullable ;
/ * *
* Interface that specifies a basic set of Hibernate operations ,
* implemented by { @link HibernateTemplate } . Not often used , but a useful
* option to enhance testability , as it can easily be mocked or stubbed .
* Interface that specifies a common set of Hibernate operations as well as
* a general { @link # execute } method for Session - based lambda expressions .
* Implemented by { @link HibernateTemplate } . Not often used , but a useful option
* to enhance testability , as it can easily be mocked or stubbed .
*
* < p > Defines { @code HibernateTemplate } ' s data access methods that
* mirror various { @link org . hibernate . Session } methods . Users are
* strongly encouraged to read the Hibernate { @code Session } javadocs
* for details on the semantics of those methods .
* < p > Defines { @code HibernateTemplate } ' s data access methods that mirror various
* { @link org . hibernate . Session } methods . Users are strongly encouraged to read the
* Hibernate { @code Session } javadocs for details on the semantics of those methods .
*
* < p > < b > A deprecation note : < / b > While { @link 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 { @link org . hibernate . Session } access code for non - trivial interactions .
* This in particular affects parameterized queries where - on Java 8 + - a custom
* { @link HibernateCallback } lambda code block with { @code createQuery } and several
* { @code setParameter } calls on the { @link org . hibernate . query . Query } interface
* is an elegant solution , to be executed via the general { @link # execute } method .
* All such operations which benefit from a lambda variant have been marked as
* { @code deprecated } on this interface .
*
* < p > < b > A Hibernate compatibility note : < / b > { @link 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 { @link # execute } method and custom lambda blocks creating the queries ,
* ideally setting named parameters through { @link org . hibernate . query . Query } .
* < b > Please be aware that deprecated operations are known to work with Hibernate
* ORM 5 . 0 - 5 . 2 but may not work with Hibernate ORM 5 . 3 and higher anymore . < / b >
*
* @author Juergen Hoeller
* @since 4 . 2
@ -560,6 +583,94 @@ public interface HibernateOperations {
@@ -560,6 +583,94 @@ public interface HibernateOperations {
void clear ( ) throws DataAccessException ;
//-------------------------------------------------------------------------
// Convenience finder methods for detached criteria
//-------------------------------------------------------------------------
/ * *
* Execute a query based on a given Hibernate criteria object .
* @param criteria the detached Hibernate criteria object .
* < b > Note : Do not reuse criteria objects ! They need to recreated per execution ,
* due to the suboptimal design of Hibernate ' s criteria facility . < / b >
* @return a { @link List } containing 0 or more persistent instances
* @throws DataAccessException in case of Hibernate errors
* @see DetachedCriteria # getExecutableCriteria ( org . hibernate . Session )
* /
List < ? > findByCriteria ( DetachedCriteria criteria ) throws DataAccessException ;
/ * *
* Execute a query based on the given Hibernate criteria object .
* @param criteria the detached Hibernate criteria object .
* < b > Note : Do not reuse criteria objects ! They need to recreated per execution ,
* due to the suboptimal design of Hibernate ' s criteria facility . < / b >
* @param firstResult the index of the first result object to be retrieved
* ( numbered from 0 )
* @param maxResults the maximum number of result objects to retrieve
* ( or < = 0 for no limit )
* @return a { @link List } containing 0 or more persistent instances
* @throws DataAccessException in case of Hibernate errors
* @see DetachedCriteria # getExecutableCriteria ( org . hibernate . Session )
* @see org . hibernate . Criteria # setFirstResult ( int )
* @see org . hibernate . Criteria # setMaxResults ( int )
* /
List < ? > findByCriteria ( DetachedCriteria criteria , int firstResult , int maxResults ) throws DataAccessException ;
/ * *
* Execute a query based on the given example entity object .
* @param exampleEntity an instance of the desired entity ,
* serving as example for "query-by-example"
* @return a { @link List } containing 0 or more persistent instances
* @throws DataAccessException in case of Hibernate errors
* @see org . hibernate . criterion . Example # create ( Object )
* /
< T > List < T > findByExample ( T exampleEntity ) throws DataAccessException ;
/ * *
* Execute a query based on the given example entity object .
* @param entityName the name of the persistent entity
* @param exampleEntity an instance of the desired entity ,
* serving as example for "query-by-example"
* @return a { @link List } containing 0 or more persistent instances
* @throws DataAccessException in case of Hibernate errors
* @see org . hibernate . criterion . Example # create ( Object )
* /
< T > List < T > findByExample ( String entityName , T exampleEntity ) throws DataAccessException ;
/ * *
* Execute a query based on a given example entity object .
* @param exampleEntity an instance of the desired entity ,
* serving as example for "query-by-example"
* @param firstResult the index of the first result object to be retrieved
* ( numbered from 0 )
* @param maxResults the maximum number of result objects to retrieve
* ( or < = 0 for no limit )
* @return a { @link List } containing 0 or more persistent instances
* @throws DataAccessException in case of Hibernate errors
* @see org . hibernate . criterion . Example # create ( Object )
* @see org . hibernate . Criteria # setFirstResult ( int )
* @see org . hibernate . Criteria # setMaxResults ( int )
* /
< T > List < T > findByExample ( T exampleEntity , int firstResult , int maxResults ) throws DataAccessException ;
/ * *
* Execute a query based on a given example entity object .
* @param entityName the name of the persistent entity
* @param exampleEntity an instance of the desired entity ,
* serving as example for "query-by-example"
* @param firstResult the index of the first result object to be retrieved
* ( numbered from 0 )
* @param maxResults the maximum number of result objects to retrieve
* ( or < = 0 for no limit )
* @return a { @link List } containing 0 or more persistent instances
* @throws DataAccessException in case of Hibernate errors
* @see org . hibernate . criterion . Example # create ( Object )
* @see org . hibernate . Criteria # setFirstResult ( int )
* @see org . hibernate . Criteria # setMaxResults ( int )
* /
< T > List < T > findByExample ( String entityName , T exampleEntity , int firstResult , int maxResults )
throws DataAccessException ;
//-------------------------------------------------------------------------
// Convenience finder methods for HQL strings
//-------------------------------------------------------------------------
@ -572,7 +683,10 @@ public interface HibernateOperations {
@@ -572,7 +683,10 @@ public interface HibernateOperations {
* @return a { @link List } containing the results of the query execution
* @throws DataAccessException in case of Hibernate errors
* @see org . hibernate . Session # createQuery
* @deprecated as of 5 . 0 . 4 , in favor of a custom { @link HibernateCallback }
* lambda code block passed to the general { @link # execute } method
* /
@Deprecated
List < ? > find ( String queryString , Object . . . values ) throws DataAccessException ;
/ * *
@ -584,7 +698,10 @@ public interface HibernateOperations {
@@ -584,7 +698,10 @@ public interface HibernateOperations {
* @return a { @link List } containing the results of the query execution
* @throws DataAccessException in case of Hibernate errors
* @see org . hibernate . Session # getNamedQuery ( String )
* @deprecated as of 5 . 0 . 4 , in favor of a custom { @link HibernateCallback }
* lambda code block passed to the general { @link # execute } method
* /
@Deprecated
List < ? > findByNamedParam ( String queryString , String paramName , Object value ) throws DataAccessException ;
/ * *
@ -596,7 +713,10 @@ public interface HibernateOperations {
@@ -596,7 +713,10 @@ public interface HibernateOperations {
* @return a { @link List } containing the results of the query execution
* @throws DataAccessException in case of Hibernate errors
* @see org . hibernate . Session # getNamedQuery ( String )
* @deprecated as of 5 . 0 . 4 , in favor of a custom { @link HibernateCallback }
* lambda code block passed to the general { @link # execute } method
* /
@Deprecated
List < ? > findByNamedParam ( String queryString , String [ ] paramNames , Object [ ] values ) throws DataAccessException ;
/ * *
@ -608,7 +728,10 @@ public interface HibernateOperations {
@@ -608,7 +728,10 @@ public interface HibernateOperations {
* @throws DataAccessException in case of Hibernate errors
* @see org . hibernate . Query # setProperties
* @see org . hibernate . Session # createQuery
* @deprecated as of 5 . 0 . 4 , in favor of a custom { @link HibernateCallback }
* lambda code block passed to the general { @link # execute } method
* /
@Deprecated
List < ? > findByValueBean ( String queryString , Object valueBean ) throws DataAccessException ;
@ -625,7 +748,10 @@ public interface HibernateOperations {
@@ -625,7 +748,10 @@ public interface HibernateOperations {
* @return a { @link List } containing the results of the query execution
* @throws DataAccessException in case of Hibernate errors
* @see org . hibernate . Session # getNamedQuery ( String )
* @deprecated as of 5 . 0 . 4 , in favor of a custom { @link HibernateCallback }
* lambda code block passed to the general { @link # execute } method
* /
@Deprecated
List < ? > findByNamedQuery ( String queryName , Object . . . values ) throws DataAccessException ;
/ * *
@ -638,7 +764,10 @@ public interface HibernateOperations {
@@ -638,7 +764,10 @@ public interface HibernateOperations {
* @return a { @link List } containing the results of the query execution
* @throws DataAccessException in case of Hibernate errors
* @see org . hibernate . Session # getNamedQuery ( String )
* @deprecated as of 5 . 0 . 4 , in favor of a custom { @link HibernateCallback }
* lambda code block passed to the general { @link # execute } method
* /
@Deprecated
List < ? > findByNamedQueryAndNamedParam ( String queryName , String paramName , Object value )
throws DataAccessException ;
@ -652,7 +781,10 @@ public interface HibernateOperations {
@@ -652,7 +781,10 @@ public interface HibernateOperations {
* @return a { @link List } containing the results of the query execution
* @throws DataAccessException in case of Hibernate errors
* @see org . hibernate . Session # getNamedQuery ( String )
* @deprecated as of 5 . 0 . 4 , in favor of a custom { @link HibernateCallback }
* lambda code block passed to the general { @link # execute } method
* /
@Deprecated
List < ? > findByNamedQueryAndNamedParam ( String queryName , String [ ] paramNames , Object [ ] values )
throws DataAccessException ;
@ -666,98 +798,13 @@ public interface HibernateOperations {
@@ -666,98 +798,13 @@ public interface HibernateOperations {
* @throws DataAccessException in case of Hibernate errors
* @see org . hibernate . Query # setProperties
* @see org . hibernate . Session # getNamedQuery ( String )
* @deprecated as of 5 . 0 . 4 , in favor of a custom { @link HibernateCallback }
* lambda code block passed to the general { @link # execute } method
* /
@Deprecated
List < ? > findByNamedQueryAndValueBean ( String queryName , Object valueBean ) throws DataAccessException ;
//-------------------------------------------------------------------------
// Convenience finder methods for detached criteria
//-------------------------------------------------------------------------
/ * *
* Execute a query based on a given Hibernate criteria object .
* @param criteria the detached Hibernate criteria object .
* < b > Note : Do not reuse criteria objects ! They need to recreated per execution ,
* due to the suboptimal design of Hibernate ' s criteria facility . < / b >
* @return a { @link List } containing 0 or more persistent instances
* @throws DataAccessException in case of Hibernate errors
* @see DetachedCriteria # getExecutableCriteria ( org . hibernate . Session )
* /
List < ? > findByCriteria ( DetachedCriteria criteria ) throws DataAccessException ;
/ * *
* Execute a query based on the given Hibernate criteria object .
* @param criteria the detached Hibernate criteria object .
* < b > Note : Do not reuse criteria objects ! They need to recreated per execution ,
* due to the suboptimal design of Hibernate ' s criteria facility . < / b >
* @param firstResult the index of the first result object to be retrieved
* ( numbered from 0 )
* @param maxResults the maximum number of result objects to retrieve
* ( or < = 0 for no limit )
* @return a { @link List } containing 0 or more persistent instances
* @throws DataAccessException in case of Hibernate errors
* @see DetachedCriteria # getExecutableCriteria ( org . hibernate . Session )
* @see org . hibernate . Criteria # setFirstResult ( int )
* @see org . hibernate . Criteria # setMaxResults ( int )
* /
List < ? > findByCriteria ( DetachedCriteria criteria , int firstResult , int maxResults ) throws DataAccessException ;
/ * *
* Execute a query based on the given example entity object .
* @param exampleEntity an instance of the desired entity ,
* serving as example for "query-by-example"
* @return a { @link List } containing 0 or more persistent instances
* @throws DataAccessException in case of Hibernate errors
* @see org . hibernate . criterion . Example # create ( Object )
* /
< T > List < T > findByExample ( T exampleEntity ) throws DataAccessException ;
/ * *
* Execute a query based on the given example entity object .
* @param entityName the name of the persistent entity
* @param exampleEntity an instance of the desired entity ,
* serving as example for "query-by-example"
* @return a { @link List } containing 0 or more persistent instances
* @throws DataAccessException in case of Hibernate errors
* @see org . hibernate . criterion . Example # create ( Object )
* /
< T > List < T > findByExample ( String entityName , T exampleEntity ) throws DataAccessException ;
/ * *
* Execute a query based on a given example entity object .
* @param exampleEntity an instance of the desired entity ,
* serving as example for "query-by-example"
* @param firstResult the index of the first result object to be retrieved
* ( numbered from 0 )
* @param maxResults the maximum number of result objects to retrieve
* ( or < = 0 for no limit )
* @return a { @link List } containing 0 or more persistent instances
* @throws DataAccessException in case of Hibernate errors
* @see org . hibernate . criterion . Example # create ( Object )
* @see org . hibernate . Criteria # setFirstResult ( int )
* @see org . hibernate . Criteria # setMaxResults ( int )
* /
< T > List < T > findByExample ( T exampleEntity , int firstResult , int maxResults ) throws DataAccessException ;
/ * *
* Execute a query based on a given example entity object .
* @param entityName the name of the persistent entity
* @param exampleEntity an instance of the desired entity ,
* serving as example for "query-by-example"
* @param firstResult the index of the first result object to be retrieved
* ( numbered from 0 )
* @param maxResults the maximum number of result objects to retrieve
* ( or < = 0 for no limit )
* @return a { @link List } containing 0 or more persistent instances
* @throws DataAccessException in case of Hibernate errors
* @see org . hibernate . criterion . Example # create ( Object )
* @see org . hibernate . Criteria # setFirstResult ( int )
* @see org . hibernate . Criteria # setMaxResults ( int )
* /
< T > List < T > findByExample ( String entityName , T exampleEntity , int firstResult , int maxResults )
throws DataAccessException ;
//-------------------------------------------------------------------------
// Convenience query methods for iteration and bulk updates/deletes
//-------------------------------------------------------------------------
@ -773,7 +820,10 @@ public interface HibernateOperations {
@@ -773,7 +820,10 @@ public interface HibernateOperations {
* @throws DataAccessException in case of Hibernate errors
* @see org . hibernate . Session # createQuery
* @see org . hibernate . Query # iterate
* @deprecated as of 5 . 0 . 4 , in favor of a custom { @link HibernateCallback }
* lambda code block passed to the general { @link # execute } method
* /
@Deprecated
Iterator < ? > iterate ( String queryString , Object . . . values ) throws DataAccessException ;
/ * *
@ -783,7 +833,10 @@ public interface HibernateOperations {
@@ -783,7 +833,10 @@ public interface HibernateOperations {
* @param it the { @code Iterator } to close
* @throws DataAccessException if the { @code Iterator } could not be closed
* @see org . hibernate . Hibernate # close
* @deprecated as of 5 . 0 . 4 , in favor of a custom { @link HibernateCallback }
* lambda code block passed to the general { @link # execute } method
* /
@Deprecated
void closeIterator ( Iterator < ? > it ) throws DataAccessException ;
/ * *
@ -795,7 +848,10 @@ public interface HibernateOperations {
@@ -795,7 +848,10 @@ public interface HibernateOperations {
* @throws DataAccessException in case of Hibernate errors
* @see org . hibernate . Session # createQuery
* @see org . hibernate . Query # executeUpdate
* @deprecated as of 5 . 0 . 4 , in favor of a custom { @link HibernateCallback }
* lambda code block passed to the general { @link # execute } method
* /
@Deprecated
int bulkUpdate ( String queryString , Object . . . values ) throws DataAccessException ;
}