我实在查看HibernateTemplate时候看到这个接口的,发现很特殊,也使用很多,然后抱着学习的态度去了解一下。
以下是对于该接口的定义,可以看出只有一个doInHibernate函数,
public interface HibernateCallback<T> {
/**
* Gets called by {@code HibernateTemplate.execute} with an active
* Hibernate {@code Session}. Does not need to care about activating
* or closing the {@code Session}, or handling transactions.
*
* <p>Allows for returning a result object created within the callback,
* i.e. a domain object or a collection of domain objects.
* A thrown custom RuntimeException is treated as an application exception:
* It gets propagated to the caller of the template.
*
* @param session active Hibernate session
* @return a result objec