The central method is {@code execute}, supporting Hibernate access code implementing the {@link HibernateCallback} interface. It provides Hibernate Sessionhandling 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 in plain Hibernate style. Hence, for newly started projects, consider adopting the standard Hibernate style of coding data access objects instead, based on {@link org.hibernate.SessionFactory#getCurrentSession()}. This HibernateTemplate primarily exists as a migration helper for Hibernate 3 based data access code, to benefit from bug fixes in Hibernate 4.x. @author Juergen Hoeller @since 4.0.1 @see #setSessionFactory @see HibernateCallback @see org.hibernate.Session @see LocalSessionFactoryBean @see HibernateTransactionManager @see org.springframework.orm.hibernate4.support.OpenSessionInViewFilter @see org.springframework.orm.hibernate4.support.OpenSessionInViewInterceptor
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|