org.springframework.orm.hibernate
Class HibernateTemplate

java.lang.Object
  extended byorg.springframework.orm.hibernate.HibernateAccessor
      extended byorg.springframework.orm.hibernate.HibernateTemplate
All Implemented Interfaces:
HibernateOperations, InitializingBean

public class HibernateTemplate
extends HibernateAccessor
implements HibernateOperations

Helper class that simplifies Hibernate data access code, and converts checked HibernateExceptions into unchecked DataAccessExceptions, compatible to the org.springframework.dao exception hierarchy. Uses the same SQLExceptionTranslator mechanism as JdbcTemplate.

Typically used to implement data access or business logic services that use Hibernate within their implementation but are Hibernate-agnostic in their interface. The latter resp. code calling the latter only have to deal with business objects, query objects, and org.springframework.dao exceptions.

The central method is "execute", supporting Hibernate 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.

This class can be considered a programmatic alternative to HibernateInterceptor. The major advantage is its straightforwardness, the major disadvantage that no checked application exceptions can get thrown from within data access code. Respective checks and the actual throwing of such exceptions can often be deferred to after callback execution, though.

Note that even if HibernateTransactionManager is used for transaction demarcation in higher-level services, all those services above the data access layer don't need need to be Hibernate-aware. Setting such a special PlatformTransactionManager is a configuration issue, without introducing code dependencies. For example, switching to JTA is just a matter of Spring configuration (use JtaTransactionManager instead), without needing to touch application code.

LocalSessionFactoryBean is the preferred way of obtaining a reference to a specific Hibernate SessionFactory, at least in a non-EJB environment.

Note: Spring's Hibernate support requires Hibernate 2.1 (as of Spring 1.0).

Since:
02.05.2003
Author:
Juergen Hoeller
See Also:
HibernateCallback, HibernateInterceptor, HibernateTransactionManager, LocalSessionFactoryBean, JndiObjectFactoryBean, Session

Field Summary
 
Fields inherited from class org.springframework.orm.hibernate.HibernateAccessor
FLUSH_AUTO, FLUSH_EAGER, FLUSH_NEVER, logger
 
Constructor Summary
HibernateTemplate()
          Create a new HibernateTemplate instance.
HibernateTemplate(net.sf.hibernate.SessionFactory sessionFactory)
          Create a new HibernateTemplate instance.
HibernateTemplate(net.sf.hibernate.SessionFactory sessionFactory, boolean allowCreate)
          Create a new HibernateTemplate instance.
 
Method Summary
 net.sf.hibernate.Criteria createCriteria(net.sf.hibernate.Session session, java.lang.Class entityClass)
          Create a Criteria object for the given Session and the given entity class.
 net.sf.hibernate.Query createQuery(net.sf.hibernate.Session session, java.lang.String queryString)
          Create a Query object for the given Session and the given query string.
 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.
 net.sf.hibernate.Query getNamedQuery(net.sf.hibernate.Session session, java.lang.String queryName)
          Create a named Query object for the given Session and the given query name.
 boolean isAllowCreate()
          Return if a new Session should be created if no thread-bound 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 setAllowCreate(boolean allowCreate)
          Set if a new Session should be created if no thread-bound found.
 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.
 
Methods inherited from class org.springframework.orm.hibernate.HibernateAccessor
afterPropertiesSet, convertHibernateAccessException, convertJdbcAccessException, flushIfNecessary, getEntityInterceptor, getFlushMode, getJdbcExceptionTranslator, getSessionFactory, setEntityInterceptor, setFlushMode, setFlushModeName, setJdbcExceptionTranslator, setSessionFactory
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HibernateTemplate

public HibernateTemplate()
Create a new HibernateTemplate instance.


HibernateTemplate

public HibernateTemplate(net.sf.hibernate.SessionFactory sessionFactory)
Create a new HibernateTemplate instance.

Parameters:
sessionFactory - SessionFactory to create Sessions

HibernateTemplate

public HibernateTemplate(net.sf.hibernate.SessionFactory sessionFactory,
                         boolean allowCreate)
Create a new HibernateTemplate instance.

Parameters:
sessionFactory - SessionFactory to create Sessions
allowCreate - if a new Session should be created if no thread-bound found
Method Detail

setAllowCreate

public void setAllowCreate(boolean allowCreate)
Set if a new Session should be created if no thread-bound found.

HibernateTemplate is aware of a respective Session bound to the current thread, for example when using HibernateTransactionManager. If allowCreate is true, a new Session will be created if none found. If false, an IllegalStateException will get thrown in this case.

See Also:
SessionFactoryUtils.getSession(SessionFactory, boolean)

isAllowCreate

public boolean isAllowCreate()
Return if a new Session should be created if no thread-bound found.


execute

public java.lang.Object execute(HibernateCallback action)
                         throws DataAccessException
Description copied from interface: HibernateOperations
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.

Specified by:
execute in interface HibernateOperations
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
Description copied from interface: HibernateOperations
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.

Specified by:
executeFind in interface HibernateOperations
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
Description copied from interface: HibernateOperations
Return the persistent instance of the given entity class with the given identifier, or null if not found.

Specified by:
get in interface HibernateOperations
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
Description copied from interface: HibernateOperations
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.

Specified by:
get in interface HibernateOperations
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
Description copied from interface: HibernateOperations
Return the persistent instance of the given entity class with the given identifier, throwing an exception if not found.

Specified by:
load in interface HibernateOperations
Parameters:
entityClass - a persistent class
id - an identifier of the persistent instance
Returns:
the persistent instance
Throws:
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
Description copied from interface: HibernateOperations
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.

Specified by:
load in interface HibernateOperations
Parameters:
entityClass - a persistent class
id - an identifier of the persistent instance
Returns:
the persistent instance
Throws:
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
Description copied from interface: HibernateOperations
Return all persistent instances of the given entity class. Note: Use queries or criteria for retrieving a specific subset.

Specified by:
loadAll in interface HibernateOperations
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
Description copied from interface: HibernateOperations
Remove the given object from the Session cache.

Specified by:
evict in interface HibernateOperations
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
Description copied from interface: HibernateOperations
Obtain the specified lock level upon the given object, implicitly checking whether the corresponding database entry still exists (throwing an OptimisticLockingFailureException if not found).

Specified by:
lock in interface HibernateOperations
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
Description copied from interface: HibernateOperations
Save the given persistent instance.

Specified by:
save in interface HibernateOperations
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
Description copied from interface: HibernateOperations
Save the given persistent instance with the given identifier.

Specified by:
save in interface HibernateOperations
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
Description copied from interface: HibernateOperations
Save respectively update the given persistent instance, according to its ID (matching the configured "unsaved-value"?).

Specified by:
saveOrUpdate in interface HibernateOperations
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
Description copied from interface: HibernateOperations
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.

Specified by:
saveOrUpdateCopy in interface HibernateOperations
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
Description copied from interface: HibernateOperations
Update the given persistent instance.

Specified by:
update in interface HibernateOperations
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
Description copied from interface: HibernateOperations
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).

Specified by:
update in interface HibernateOperations
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
Description copied from interface: HibernateOperations
Delete the given persistent instance.

Specified by:
delete in interface HibernateOperations
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
Description copied from interface: HibernateOperations
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).

Specified by:
delete in interface HibernateOperations
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
Description copied from interface: HibernateOperations
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.

Specified by:
deleteAll in interface HibernateOperations
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
Description copied from interface: HibernateOperations
Execute a query for persistent instances.

Specified by:
find in interface HibernateOperations
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
Description copied from interface: HibernateOperations
Execute a query for persistent instances, binding one value to a "?" parameter in the query string.

Specified by:
find in interface HibernateOperations
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
Description copied from interface: HibernateOperations
Execute a query for persistent instances, binding one value to a "?" parameter of the given type in the query string.

Specified by:
find in interface HibernateOperations
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
Description copied from interface: HibernateOperations
Execute a query for persistent instances, binding a number of values to "?" parameters in the query string.

Specified by:
find in interface HibernateOperations
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
Description copied from interface: HibernateOperations
Execute a query for persistent instances, binding a number of values to "?" parameters of the given types in the query string.

Specified by:
find in interface HibernateOperations
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
Description copied from interface: HibernateOperations
Execute a query for persistent instances, binding the properties of the given bean to named parameters in the query string.

Specified by:
findByValueBean in interface HibernateOperations
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
Description copied from interface: HibernateOperations
Execute a named query for persistent instances. A named query is defined in a Hibernate mapping file.

Specified by:
findByNamedQuery in interface HibernateOperations
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
Description copied from interface: HibernateOperations
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.

Specified by:
findByNamedQuery in interface HibernateOperations
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
Description copied from interface: HibernateOperations
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.

Specified by:
findByNamedQuery in interface HibernateOperations
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
Description copied from interface: HibernateOperations
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.

Specified by:
findByNamedQuery in interface HibernateOperations
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
Description copied from interface: HibernateOperations
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.

Specified by:
findByNamedQuery in interface HibernateOperations
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
Description copied from interface: HibernateOperations
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.

Specified by:
findByNamedQueryAndValueBean in interface HibernateOperations
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)

createQuery

public net.sf.hibernate.Query createQuery(net.sf.hibernate.Session session,
                                          java.lang.String queryString)
                                   throws net.sf.hibernate.HibernateException
Create a Query object for the given Session and the given query string. To be used within a HibernateCallback.

Applies a transaction timeout, if any. If you don't use such timeouts, the call is equivalent to Session.createQuery.

Parameters:
session - current Hibernate Session
queryString - the HQL query string
Returns:
the Query object
Throws:
net.sf.hibernate.HibernateException - if the Query could not be created
See Also:
HibernateCallback.doInHibernate(net.sf.hibernate.Session), Session.createQuery(java.lang.String)

getNamedQuery

public net.sf.hibernate.Query getNamedQuery(net.sf.hibernate.Session session,
                                            java.lang.String queryName)
                                     throws net.sf.hibernate.HibernateException
Create a named Query object for the given Session and the given query name. To be used within a HibernateCallback.

Applies a transaction timeout, if any. If you don't use such timeouts, the call is equivalent to Session.getNamedQuery.

Parameters:
session - current Hibernate Session
queryName - the name of the query in the Hibernate mapping file
Returns:
the Query object
Throws:
net.sf.hibernate.HibernateException - if the Query could not be created
See Also:
HibernateCallback.doInHibernate(net.sf.hibernate.Session), Session.getNamedQuery(java.lang.String)

createCriteria

public net.sf.hibernate.Criteria createCriteria(net.sf.hibernate.Session session,
                                                java.lang.Class entityClass)
                                         throws net.sf.hibernate.HibernateException
Create a Criteria object for the given Session and the given entity class. To be used within a HibernateCallback.

Applies a transaction timeout, if any. If you don't use such timeouts, the call is equivalent to Session.createCriteria.

Parameters:
session - current Hibernate Session
entityClass - the entity class to create the Criteria for
Returns:
the Query object
Throws:
net.sf.hibernate.HibernateException - if the Criteria could not be created
See Also:
HibernateCallback.doInHibernate(net.sf.hibernate.Session), Session.createCriteria(java.lang.Class)


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