org.springframework.orm.hibernate
Interface HibernateOperations

All Known Implementing Classes:
HibernateTemplate

public interface HibernateOperations

Interface that specifies a basic set of Hibernate operations. Implemented by HibernateTemplate. Not often used, but a useful option to enhance testability, as it can easily be mocked or stubbed.

Provides HibernateTemplate's convenience methods that mirror various Session methods.

Since:
05.02.2004
Author:
Juergen Hoeller
See Also:
HibernateTemplate, Session

Method Summary
 void delete(java.lang.Object entity)
          Delete the given persistent instance.
 void delete(java.lang.Object entity, net.sf.hibernate.LockMode lockMode)
          Delete the given persistent instance.
 void deleteAll(java.util.Collection entities)
          Delete all given persistent instances.
 void evict(java.lang.Object entity)
          Remove the given object from the Session cache.
 java.lang.Object execute(HibernateCallback action)
          Execute the action specified by the given action object within a session.
 java.util.List executeFind(HibernateCallback action)
          Execute the specified action assuming that the result object is a List.
 java.util.List find(java.lang.String queryString)
          Execute a query for persistent instances.
 java.util.List find(java.lang.String queryString, java.lang.Object value)
          Execute a query for persistent instances, binding one value to a "?" parameter in the query string.
 java.util.List find(java.lang.String queryString, java.lang.Object[] values)
          Execute a query for persistent instances, binding a number of values to "?" parameters in the query string.
 java.util.List find(java.lang.String queryString, java.lang.Object[] values, net.sf.hibernate.type.Type[] types)
          Execute a query for persistent instances, binding a number of values to "?" parameters of the given types in the query string.
 java.util.List find(java.lang.String queryString, java.lang.Object value, net.sf.hibernate.type.Type type)
          Execute a query for persistent instances, binding one value to a "?" parameter of the given type in the query string.
 java.util.List findByNamedQuery(java.lang.String queryName)
          Execute a named query for persistent instances.
 java.util.List findByNamedQuery(java.lang.String queryName, java.lang.Object value)
          Execute a named query for persistent instances, binding one value to a "?" parameter in the query string.
 java.util.List findByNamedQuery(java.lang.String queryName, java.lang.Object[] values)
          Execute a named query for persistent instances, binding a number of values to "?" parameters in the query string.
 java.util.List findByNamedQuery(java.lang.String queryName, java.lang.Object[] values, net.sf.hibernate.type.Type[] types)
          Execute a named query for persistent instances, binding a number of values to "?" parameters in the query string.
 java.util.List findByNamedQuery(java.lang.String queryName, java.lang.Object value, net.sf.hibernate.type.Type type)
          Execute a named query for persistent instances, binding one value to a "?" parameter in the query string.
 java.util.List findByNamedQueryAndValueBean(java.lang.String queryName, java.lang.Object valueBean)
          Execute a named query for persistent instances, binding the properties of the given bean to named parameters in the query string.
 java.util.List findByValueBean(java.lang.String queryString, java.lang.Object valueBean)
          Execute a query for persistent instances, binding the properties of the given bean to named parameters in the query string.
 java.lang.Object get(java.lang.Class entityClass, java.io.Serializable id)
          Return the persistent instance of the given entity class with the given identifier, or null if not found.
 java.lang.Object get(java.lang.Class entityClass, java.io.Serializable id, net.sf.hibernate.LockMode lockMode)
          Return the persistent instance of the given entity class with the given identifier, or null if not found.
 java.lang.Object load(java.lang.Class entityClass, java.io.Serializable id)
          Return the persistent instance of the given entity class with the given identifier, throwing an exception if not found.
 java.lang.Object load(java.lang.Class entityClass, java.io.Serializable id, net.sf.hibernate.LockMode lockMode)
          Return the persistent instance of the given entity class with the given identifier, throwing an exception if not found.
 java.util.List loadAll(java.lang.Class entityClass)
          Return all persistent instances of the given entity class.
 void lock(java.lang.Object entity, net.sf.hibernate.LockMode lockMode)
          Obtain the specified lock level upon the given object, implicitly checking whether the corresponding database entry still exists (throwing an OptimisticLockingFailureException if not found).
 java.io.Serializable save(java.lang.Object entity)
          Save the given persistent instance.
 void save(java.lang.Object entity, java.io.Serializable id)
          Save the given persistent instance with the given identifier.
 void saveOrUpdate(java.lang.Object entity)
          Save respectively update the given persistent instance, according to its ID (matching the configured "unsaved-value"?).
 java.lang.Object saveOrUpdateCopy(java.lang.Object entity)
          Save respectively update the contents of given persistent object, according to its ID (matching the configured "unsaved-value"?).
 void update(java.lang.Object entity)
          Update the given persistent instance.
 void update(java.lang.Object entity, net.sf.hibernate.LockMode lockMode)
          Update the given persistent instance.
 

Method Detail

execute

public java.lang.Object execute(HibernateCallback action)
                         throws DataAccessException
Execute the action specified by the given action object within a session. Application exceptions thrown by the action object get propagated to the caller (can only be unchecked). Hibernate exceptions are transformed into appropriate DAO ones. Allows for returning a result object, i.e. a domain object or a collection of domain objects.

Note: Callback code is not supposed to handle transactions itself! Use an appropriate transaction manager like HibernateTransactionManager. Generally, callback code must not touch any Session lifecycle methods, like close, disconnect, or reconnect, to let the template do its work.

Parameters:
action - callback object that specifies the Hibernate action
Returns:
a result object returned by the action, or null
Throws:
DataAccessException - in case of Hibernate errors
See Also:
HibernateTransactionManager, org.springframework.dao, org.springframework.transaction

executeFind

public java.util.List executeFind(HibernateCallback action)
                           throws DataAccessException
Execute the specified action assuming that the result object is a List.

This is a convenience method for executing Hibernate find calls within an action.

Parameters:
action - action object that specifies the Hibernate action
Returns:
a result object returned by the action, or null
Throws:
DataAccessException - in case of Hibernate errors

get

public java.lang.Object get(java.lang.Class entityClass,
                            java.io.Serializable id)
                     throws DataAccessException
Return the persistent instance of the given entity class with the given identifier, or null if not found.

Parameters:
entityClass - a persistent class
id - an identifier of the persistent instance
Returns:
the persistent instance, or null if not found
Throws:
DataAccessException - in case of Hibernate errors
See Also:
Session.get(Class, java.io.Serializable)

get

public java.lang.Object get(java.lang.Class entityClass,
                            java.io.Serializable id,
                            net.sf.hibernate.LockMode lockMode)
                     throws DataAccessException
Return the persistent instance of the given entity class with the given identifier, or null if not found. Obtains the specified lock mode if the instance exists.

Parameters:
entityClass - a persistent class
id - an identifier of the persistent instance
Returns:
the persistent instance, or null if not found
Throws:
DataAccessException - in case of Hibernate errors
See Also:
Session.get(Class, java.io.Serializable, net.sf.hibernate.LockMode)

load

public java.lang.Object load(java.lang.Class entityClass,
                             java.io.Serializable id)
                      throws DataAccessException
Return the persistent instance of the given entity class with the given identifier, throwing an exception if not found.

Parameters:
entityClass - a persistent class
id - an identifier of the persistent instance
Returns:
the persistent instance
Throws:
HibernateObjectRetrievalFailureException - if the instance could not be found
DataAccessException - in case of Hibernate errors
See Also:
Session.load(Class, java.io.Serializable)

load

public java.lang.Object load(java.lang.Class entityClass,
                             java.io.Serializable id,
                             net.sf.hibernate.LockMode lockMode)
                      throws DataAccessException
Return the persistent instance of the given entity class with the given identifier, throwing an exception if not found. Obtains the specified lock mode if the instance exists.

Parameters:
entityClass - a persistent class
id - an identifier of the persistent instance
Returns:
the persistent instance
Throws:
HibernateObjectRetrievalFailureException - if the instance could not be found
DataAccessException - in case of Hibernate errors
See Also:
Session.load(Class, java.io.Serializable)

loadAll

public java.util.List loadAll(java.lang.Class entityClass)
                       throws DataAccessException
Return all persistent instances of the given entity class. Note: Use queries or criteria for retrieving a specific subset.

Parameters:
entityClass - a persistent class
Returns:
a List containing 0 or more persistent instances
Throws:
DataAccessException - if there is a Hibernate error
See Also:
Session.createCriteria(java.lang.Class)

evict

public void evict(java.lang.Object entity)
           throws DataAccessException
Remove the given object from the Session cache.

Parameters:
entity - the persistent instance to lock
Throws:
DataAccessException - in case of Hibernate errors
See Also:
Session.evict(Object)

lock

public void lock(java.lang.Object entity,
                 net.sf.hibernate.LockMode lockMode)
          throws DataAccessException
Obtain the specified lock level upon the given object, implicitly checking whether the corresponding database entry still exists (throwing an OptimisticLockingFailureException if not found).

Parameters:
entity - the persistent instance to lock
Throws:
DataAccessException - in case of Hibernate errors
See Also:
HibernateOptimisticLockingFailureException, Session.lock(Object, net.sf.hibernate.LockMode)

save

public java.io.Serializable save(java.lang.Object entity)
                          throws DataAccessException
Save the given persistent instance.

Parameters:
entity - the persistent instance to save
Returns:
the generated identifier
Throws:
DataAccessException - in case of Hibernate errors
See Also:
Session.save(Object)

save

public void save(java.lang.Object entity,
                 java.io.Serializable id)
          throws DataAccessException
Save the given persistent instance with the given identifier.

Parameters:
entity - the persistent instance to save
id - the identifier to assign
Throws:
DataAccessException - in case of Hibernate errors
See Also:
Session.save(Object, java.io.Serializable)

saveOrUpdate

public void saveOrUpdate(java.lang.Object entity)
                  throws DataAccessException
Save respectively update the given persistent instance, according to its ID (matching the configured "unsaved-value"?).

Parameters:
entity - the persistent instance to save respectively update (to be associated with the Hibernate Session)
Throws:
DataAccessException - in case of Hibernate errors
See Also:
Session.saveOrUpdate(Object)

saveOrUpdateCopy

public java.lang.Object saveOrUpdateCopy(java.lang.Object entity)
                                  throws DataAccessException
Save respectively update the contents of given persistent object, according to its ID (matching the configured "unsaved-value"?). Will copy the contained fields to an already loaded instance with the same ID, if appropriate.

Parameters:
entity - the persistent object to save respectively update (not necessarily to be associated with the Hibernate Session)
Returns:
the actually associated persistent object (either an already loaded instance with the same ID, or the given object)
Throws:
DataAccessException - in case of Hibernate errors
See Also:
Session.saveOrUpdateCopy(Object)

update

public void update(java.lang.Object entity)
            throws DataAccessException
Update the given persistent instance.

Parameters:
entity - the persistent instance to update
Throws:
DataAccessException - in case of Hibernate errors
See Also:
Session.update(Object)

update

public void update(java.lang.Object entity,
                   net.sf.hibernate.LockMode lockMode)
            throws DataAccessException
Update the given persistent instance. Obtains the specified lock mode if the instance exists, implicitly checking whether the corresponding database entry still exists (throwing an OptimisticLockingFailureException if not found).

Parameters:
entity - the persistent instance to update
Throws:
DataAccessException - in case of Hibernate errors
See Also:
HibernateOptimisticLockingFailureException, Session.update(Object)

delete

public void delete(java.lang.Object entity)
            throws DataAccessException
Delete the given persistent instance.

Parameters:
entity - the persistent instance to delete
Throws:
DataAccessException - in case of Hibernate errors
See Also:
Session.delete(Object)

delete

public void delete(java.lang.Object entity,
                   net.sf.hibernate.LockMode lockMode)
            throws DataAccessException
Delete the given persistent instance. Obtains the specified lock mode if the instance exists, implicitly checking whether the corresponding database entry still exists (throwing an OptimisticLockingFailureException if not found).

Parameters:
entity - the persistent instance to delete
Throws:
DataAccessException - in case of Hibernate errors
See Also:
HibernateOptimisticLockingFailureException, Session.delete(Object)

deleteAll

public void deleteAll(java.util.Collection entities)
               throws DataAccessException
Delete all given persistent instances. This can be combined with any of the find methods to delete by query in two lines of code, similar to Session's delete by query methods.

Parameters:
entities - the persistent instances to delete
Throws:
DataAccessException - in case of Hibernate errors
See Also:
Session.delete(String)

find

public java.util.List find(java.lang.String queryString)
                    throws DataAccessException
Execute a query for persistent instances.

Parameters:
queryString - a query expressed in Hibernate's query language
Returns:
a List containing 0 or more persistent instances
Throws:
DataAccessException - in case of Hibernate errors
See Also:
Session.find(String), Session.createQuery(java.lang.String)

find

public java.util.List find(java.lang.String queryString,
                           java.lang.Object value)
                    throws DataAccessException
Execute a query for persistent instances, binding one value to a "?" parameter in the query string.

Parameters:
queryString - a query expressed in Hibernate's query language
value - the value of the parameter
Returns:
a List containing 0 or more persistent instances
Throws:
DataAccessException - in case of Hibernate errors
See Also:
Session.find(String), Session.createQuery(java.lang.String)

find

public java.util.List find(java.lang.String queryString,
                           java.lang.Object value,
                           net.sf.hibernate.type.Type type)
                    throws DataAccessException
Execute a query for persistent instances, binding one value to a "?" parameter of the given type in the query string.

Parameters:
queryString - a query expressed in Hibernate's query language
value - the value of the parameter
type - Hibernate type of the parameter
Returns:
a List containing 0 or more persistent instances
Throws:
DataAccessException - in case of Hibernate errors
See Also:
Session.find(String), Session.createQuery(java.lang.String)

find

public java.util.List find(java.lang.String queryString,
                           java.lang.Object[] values)
                    throws DataAccessException
Execute a query for persistent instances, binding a number of values to "?" parameters in the query string.

Parameters:
queryString - a query expressed in Hibernate's query language
values - the values of the parameters
Returns:
a List containing 0 or more persistent instances
Throws:
DataAccessException - in case of Hibernate errors
See Also:
Session.find(String), Session.createQuery(java.lang.String)

find

public java.util.List find(java.lang.String queryString,
                           java.lang.Object[] values,
                           net.sf.hibernate.type.Type[] types)
                    throws DataAccessException
Execute a query for persistent instances, binding a number of values to "?" parameters of the given types in the query string.

Parameters:
queryString - a query expressed in Hibernate's query language
values - the values of the parameters
types - Hibernate types of the parameters
Returns:
a List containing 0 or more persistent instances
Throws:
DataAccessException - in case of Hibernate errors
See Also:
Session.find(String), Session.createQuery(java.lang.String)

findByValueBean

public java.util.List findByValueBean(java.lang.String queryString,
                                      java.lang.Object valueBean)
                               throws DataAccessException
Execute a query for persistent instances, binding the properties of the given bean to named parameters in the query string.

Parameters:
queryString - a query expressed in Hibernate's query language
valueBean - the values of the parameters
Returns:
a List containing 0 or more persistent instances
Throws:
DataAccessException - in case of Hibernate errors
See Also:
Session.find(String), Session.createQuery(java.lang.String), Query.setProperties(java.lang.Object)

findByNamedQuery

public java.util.List findByNamedQuery(java.lang.String queryName)
                                throws DataAccessException
Execute a named query for persistent instances. A named query is defined in a Hibernate mapping file.

Parameters:
queryName - the name of a Hibernate query in a mapping file
Returns:
a List containing 0 or more persistent instances
Throws:
DataAccessException - in case of Hibernate errors
See Also:
Session.find(String), Session.getNamedQuery(String)

findByNamedQuery

public java.util.List findByNamedQuery(java.lang.String queryName,
                                       java.lang.Object value)
                                throws DataAccessException
Execute a named query for persistent instances, binding one value to a "?" parameter in the query string. A named query is defined in a Hibernate mapping file.

Parameters:
queryName - the name of a Hibernate query in a mapping file
Returns:
a List containing 0 or more persistent instances
Throws:
DataAccessException - in case of Hibernate errors
See Also:
Session.find(String), Session.getNamedQuery(String)

findByNamedQuery

public java.util.List findByNamedQuery(java.lang.String queryName,
                                       java.lang.Object value,
                                       net.sf.hibernate.type.Type type)
                                throws DataAccessException
Execute a named query for persistent instances, binding one value to a "?" parameter in the query string. A named query is defined in a Hibernate mapping file.

Parameters:
queryName - the name of a Hibernate query in a mapping file
type - Hibernate type of the parameter
Returns:
a List containing 0 or more persistent instances
Throws:
DataAccessException - in case of Hibernate errors
See Also:
Session.find(String), Session.getNamedQuery(String)

findByNamedQuery

public java.util.List findByNamedQuery(java.lang.String queryName,
                                       java.lang.Object[] values)
                                throws DataAccessException
Execute a named query for persistent instances, binding a number of values to "?" parameters in the query string. A named query is defined in a Hibernate mapping file.

Parameters:
queryName - the name of a Hibernate query in a mapping file
values - the values of the parameters
Returns:
a List containing 0 or more persistent instances
Throws:
DataAccessException - in case of Hibernate errors
See Also:
Session.find(String), Session.getNamedQuery(String)

findByNamedQuery

public java.util.List findByNamedQuery(java.lang.String queryName,
                                       java.lang.Object[] values,
                                       net.sf.hibernate.type.Type[] types)
                                throws DataAccessException
Execute a named query for persistent instances, binding a number of values to "?" parameters in the query string. A named query is defined in a Hibernate mapping file.

Parameters:
queryName - the name of a Hibernate query in a mapping file
values - the values of the parameters
types - Hibernate types of the parameters
Returns:
a List containing 0 or more persistent instances
Throws:
DataAccessException - in case of Hibernate errors
See Also:
Session.find(String), Session.getNamedQuery(String)

findByNamedQueryAndValueBean

public java.util.List findByNamedQueryAndValueBean(java.lang.String queryName,
                                                   java.lang.Object valueBean)
                                            throws DataAccessException
Execute a named query for persistent instances, binding the properties of the given bean to named parameters in the query string. A named query is defined in a Hibernate mapping file.

Parameters:
queryName - the name of a Hibernate query in a mapping file
valueBean - the values of the parameters
Returns:
a List containing 0 or more persistent instances
Throws:
DataAccessException - in case of Hibernate errors
See Also:
Session.find(String), Session.getNamedQuery(String), Query.setProperties(java.lang.Object)


Copyright (C) 2003-2004 The Spring Framework Project.