org.springframework.dao exception hierarchy.
The central method is execute, supporting Hibernate access code
implementing the HibernateCallback interface. It provides Hibernate Session
handling such that neither the HibernateCallback implementation nor the calling
code needs to explicitly care about retrieving/closing Hibernate Sessions,
or handling Session lifecycle exceptions. For typical single step actions,
there are various convenience methods (find, load, saveOrUpdate, delete).
Can be used within a service implementation via direct instantiation with a SessionFactory reference, or get prepared in an application context and given to services as bean reference.
Note
The SessionFactory should always be configured as bean in the application context, in the first case given to the service directly, in the second case to the prepared template.
Note
Hibernate access code can also be coded against the native Hibernate
Session. Hence, for newly started projects, consider adopting the standard
Hibernate style of coding against SessionFactory#getCurrentSession().
Alternatively, use execute(HibernateCallback) with Java 8 lambda code blocks
against the callback-provided Session which results in elegant code as well,
decoupled from the Hibernate Session lifecycle. The remaining operations on this
HibernateTemplate are deprecated in the meantime and primarily exist as a migration
helper for older Hibernate 3.x/4.x data access code in existing applications.
setSessionFactory, HibernateCallback, Session, LocalSessionFactoryBean, HibernateTransactionManager, org.springframework.orm.hibernate5.support.OpenSessionInViewFilter , org.springframework.orm.hibernate5.support.OpenSessionInViewInterceptor
| Modifier and Type | Class and Description |
|---|---|
| private class | HibernateTemplate.CloseSuppressingInvocationHandler
Invocation handler that suppresses close calls on Hibernate Sessions. |
| Modifier and Type | Field and Description |
|---|---|
| private boolean | |
| private boolean | |
| private boolean | |
| private int | |
| private String[] | |
| protected final Log | |
| private int | |
| private String | |
| private SessionFactory | sessionFactory
Deprecated
as a consequence of
SessionFactory being deprecated.
|
| Access | Constructor and Description |
|---|---|
| public | |
| public | HibernateTemplate(SessionFactory
the SessionFactory to create Sessions with sessionFactory)
Deprecated
as a consequence of
Create a new HibernateTemplate instance.
SessionFactory being deprecated.
|
| Modifier and Type | Method and Description |
|---|---|
| public void | afterPropertiesSet()
Implements org. BeanFactory after it has set all bean properties
and satisfied BeanFactoryAware, ApplicationContextAware etc.
This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set. |
| protected void | applyNamedParameterToQuery(Query<?>
the Query object queryObject, String the name of the parameter paramName, Object the value of the parameter value)
Deprecated
as a consequence of
Apply the given name parameter to the given Query object.
Query being deprecated.
|
| public int | bulkUpdate(String
an update/delete query expressed in Hibernate's query language queryString, Object... the values of the parameters values)Implements org.
Deprecated
Update/delete all objects according to the given query, binding a number of
values to "?" parameters in the query string.
|
| protected void | checkWriteOperationAllowed(Session
current Hibernate Session session)
Deprecated
as a consequence of
Check whether write operations are allowed on the given Session.
Session being deprecated.
|
| public void | clear()
Implements org. org. cache, and
cancel all pending saves, updates and deletes.
|
| public void | closeIterator(Iterator<?>
the it)Iterator to closeImplements org.
Deprecated
Immediately close an Iterator created by any of the various
iterate(..) operations, instead of waiting until the
session is closed or disconnected.
|
| public boolean | contains(Object
the persistence instance to check entity)Implements org. |
| protected Session | Returns: the Session proxythe Hibernate Session to create a proxy for session)
Deprecated
as a consequence of
Create a close-suppressing proxy for the given Hibernate Session.
Session being deprecated.
|
| public void | delete(Object
the persistent instance to delete entity)Implements org. |
| public void | delete(Object
the persistent instance to delete entity, LockMode the lock mode to obtain lockMode)Implements org. |
| public void | delete(String
the name of the persistent entity entityName, Object the persistent instance to delete entity)Implements org. |
| public void | delete(String
the name of the persistent entity entityName, Object the persistent instance to delete entity, LockMode the lock mode to obtain lockMode)Implements org. |
| public void | deleteAll(Collection<?>
the persistent instances to delete entities)Implements org. |
| protected void | disableFilters(Session
the current Hibernate Session session)
Deprecated
as a consequence of
Disable the specified filters on the given Session.
Session being deprecated.
|
| protected <T> T | Returns: a result object returned by the action, ornullcallback object that specifies the Hibernate action action, boolean whether to enforce exposure of the native
Hibernate Session to callback code enforceNativeSession)Execute the action specified by the given action object within a Session. |
| public Filter | enableFilter(String
the name of the filter filterName)Implements org. Filter for the given filter name.
|
| protected void | enableFilters(Session
the current Hibernate Session session)
Deprecated
as a consequence of
Enable the specified filters on the given Session.
Session being deprecated.
|
| public void | evict(Object
the persistent instance to evict entity)Implements org. org. cache.
|
| public <T> T | execute(HibernateCallback<T>
callback object that specifies the Hibernate action action)Implements org. org..
|
| public <T> T | Returns: a result object returned by the action, ornullcallback object that specifies the Hibernate action action)Execute the action specified by the given action object within a
native |
| public List | find(String
a query expressed in Hibernate's query language queryString, Object... the values of the parameters values)Implements org.
Deprecated
Execute an HQL query, binding a number of values to "?" parameters
in the query string.
|
| public List | findByCriteria(DetachedCriteria
the detached Hibernate criteria object. criteria)Note Do not reuse criteria objects! They need to recreated per execution, due to the suboptimal design of Hibernate's criteria facility. Implements org. |
| public List | findByCriteria(DetachedCriteria
the detached Hibernate criteria object. criteria, int Note Do not reuse criteria objects! They need to recreated per execution, due to the suboptimal design of Hibernate's criteria facility. the index of the first result object to be retrieved
(numbered from 0) firstResult, int the maximum number of result objects to retrieve
(or <=0 for no limit) maxResults)Implements org. |
| public <T> List | findByExample(T
an instance of the desired entity,
serving as example for "query-by-example" exampleEntity)Implements org. |
| public <T> List | findByExample(String
the name of the persistent entity entityName, T an instance of the desired entity,
serving as example for "query-by-example" exampleEntity)Implements org. |
| public <T> List | findByExample(T
an instance of the desired entity,
serving as example for "query-by-example" exampleEntity, int the index of the first result object to be retrieved
(numbered from 0) firstResult, int the maximum number of result objects to retrieve
(or <=0 for no limit) maxResults)Implements org. |
| public <T> List | findByExample(String
the name of the persistent entity entityName, T an instance of the desired entity,
serving as example for "query-by-example" exampleEntity, int the index of the first result object to be retrieved
(numbered from 0) firstResult, int the maximum number of result objects to retrieve
(or <=0 for no limit) maxResults)Implements org. |
| public List | findByNamedParam(String
a query expressed in Hibernate's query language queryString, String the name of the parameter paramName, Object the value of the parameter value)Implements org.
Deprecated
Execute an HQL query, binding one value to a ":" named parameter
in the query string.
|
| public List | findByNamedParam(String
a query expressed in Hibernate's query language queryString, String[] the names of the parameters paramNames, Object[] the values of the parameters values)Implements org.
Deprecated
Execute an HQL query, binding a number of values to ":" named
parameters in the query string.
|
| public List | findByNamedQuery(String
the name of a Hibernate query in a mapping file queryName, Object... the values of the parameters values)Implements org.
Deprecated
Execute a named query binding a number of values to "?" parameters
in the query string.
|
| public List | findByNamedQueryAndNamedParam(String
the name of a Hibernate query in a mapping file queryName, String the name of parameter paramName, Object the value of the parameter value)Implements org.
Deprecated
Execute a named query, binding one value to a ":" named parameter
in the query string.
|
| public List | findByNamedQueryAndNamedParam(String
the name of a Hibernate query in a mapping file queryName, String[] the names of the parameters paramNames, Object[] the values of the parameters values)Implements org.
Deprecated
Execute a named query, binding a number of values to ":" named
parameters in the query string.
|
| public List | findByNamedQueryAndValueBean(String
the name of a Hibernate query in a mapping file queryName, Object the values of the parameters valueBean)Implements org.
Deprecated
Execute a named query, binding the properties of the given bean to
":" named parameters in the query string.
|
| public List | findByValueBean(String
a query expressed in Hibernate's query language queryString, Object the values of the parameters valueBean)Implements org.
Deprecated
Execute an HQL query, binding the properties of the given bean to
named parameters in the query string.
|
| public void | flush()
Implements org. |
| public <T> T | get(Class<T>
a persistent class entityClass, Serializable the identifier of the persistent instance id)Implements org. null if not found.
|
| public <T> T | get(Class<T>
a persistent class entityClass, Serializable the identifier of the persistent instance id, LockMode the lock mode to obtain lockMode)Implements org. null if not found.
|
| public Object | get(String
the name of the persistent entity entityName, Serializable the identifier of the persistent instance id)Implements org. null if not found.
|
| public Object | get(String
the name of the persistent entity entityName, Serializable the identifier of the persistent instance id, LockMode the lock mode to obtain lockMode)Implements org. null if not found.
|
| public int | |
| public String[] | |
| public int | |
| public String | |
| public SessionFactory | getSessionFactory()
Deprecated
as a consequence of
Return the Hibernate SessionFactory that should be used to create
Hibernate Sessions.
SessionFactory being deprecated.
|
| public void | initialize(Object
a proxy for a persistent object or a persistent collection proxy)Implements org. |
| public boolean | |
| public boolean | isCheckWriteOperations()
Return whether to check that the Hibernate Session is not in read-only mode in case of write operations (save/update/delete). |
| public boolean | isExposeNativeSession()
Return whether to expose the native Hibernate Session to HibernateCallback code, or rather a Session proxy. |
| public Iterator | iterate(String
a query expressed in Hibernate's query language queryString, Object... the values of the parameters values)Implements org.
Deprecated
Execute a query for persistent instances, binding a number of
values to "?" parameters in the query string.
|
| public <T> T | load(Class<T>
a persistent class entityClass, Serializable the identifier of the persistent instance id)Implements org. |
| public <T> T | load(Class<T>
a persistent class entityClass, Serializable the identifier of the persistent instance id, LockMode the lock mode to obtain lockMode)Implements org. |
| public Object | load(String
the name of the persistent entity entityName, Serializable the identifier of the persistent instance id)Implements org. |
| public Object | load(String
the name of the persistent entity entityName, Serializable the identifier of the persistent instance id, LockMode the lock mode to obtain lockMode)Implements org. |
| public void | load(Object
the object (of the target class) to load into entity, Serializable the identifier of the persistent instance id)Implements org. |
| public <T> List | loadAll(Class<T>
a persistent class entityClass)Implements org. |
| public void | lock(Object
the persistent instance to lock entity, LockMode the lock mode to obtain lockMode)Implements org. |
| public void | lock(String
the name of the persistent entity entityName, Object the persistent instance to lock entity, LockMode the lock mode to obtain lockMode)Implements org. |
| public <T> T | merge(T
the object to merge with the corresponding persistence instance entity)Implements org. |
| public <T> T | merge(String
the name of the persistent entity entityName, T the object to merge with the corresponding persistence instance entity)Implements org. |
| private static <T> T | |
| protected final SessionFactory | Returns: the SessionFactory (nevernull)
Deprecated
as a consequence of
Obtain the SessionFactory for actual use.
SessionFactory being deprecated.
|
| public void | persist(Object
the persistent instance to persist entity)Implements org. |
| public void | persist(String
the name of the persistent entity entityName, Object the persistent instance to persist entity)Implements org. |
| protected void | prepareCriteria(Criteria
the Criteria object to prepare criteria)Prepare the given Criteria object, applying cache settings and/or a transaction timeout. |
| protected void | prepareQuery(Query<?>
the Query object to prepare queryObject)
Deprecated
as a consequence of
Prepare the given Query object, applying cache settings and/or
a transaction timeout.
Query being deprecated.
|
| public void | refresh(Object
the persistent instance to re-read entity)Implements org. |
| public void | refresh(Object
the persistent instance to re-read entity, LockMode the lock mode to obtain lockMode)Implements org. |
| public void | replicate(Object
the persistent object to replicate entity, ReplicationMode the Hibernate ReplicationMode replicationMode)Implements org. |
| public void | replicate(String
the name of the persistent entity entityName, Object the persistent object to replicate entity, ReplicationMode the Hibernate ReplicationMode replicationMode)Implements org. |
| public Serializable | save(Object
the transient instance to persist entity)Implements org. |
| public Serializable | save(String
the name of the persistent entity entityName, Object the transient instance to persist entity)Implements org. |
| public void | saveOrUpdate(Object
the persistent instance to save or update
(to be associated with the Hibernate entity)Session)Implements org. |
| public void | saveOrUpdate(String
the name of the persistent entity entityName, Object the persistent instance to save or update
(to be associated with the Hibernate entity)Session)Implements org. |
| public void | |
| public void | setCheckWriteOperations(boolean checkWriteOperations)
Set whether to check that the Hibernate Session is not in read-only mode in case of write operations (save/update/delete). |
| public void | setExposeNativeSession(boolean exposeNativeSession)
Set whether to expose the native Hibernate Session to HibernateCallback code. |
| public void | |
| public void | setFilterNames(String... filterNames)
Set one or more names of Hibernate filters to be activated for all Sessions that this accessor works with. |
| public void | |
| public void | setQueryCacheRegion(String queryCacheRegion)
Set the name of the cache region for queries executed by this template. |
| public void | setSessionFactory(SessionFactory sessionFactory)
Deprecated
as a consequence of
Set the Hibernate SessionFactory that should be used to create
Hibernate Sessions.
SessionFactory being deprecated.
|
| public void | update(Object
the persistent instance to update entity)Implements org. org..
|
| public void | update(Object
the persistent instance to update entity, LockMode the lock mode to obtain lockMode)Implements org. org..
|
| public void | update(String
the name of the persistent entity entityName, Object the persistent instance to update entity)Implements org. org..
|
| public void | update(String
the name of the persistent entity entityName, Object the persistent instance to update entity, LockMode the lock mode to obtain lockMode)Implements org. org..
|