This is meant to be used in a HibernateCallback (which is stated in the javadoc). For example:
Code:
List result = getHibernateTemplate().executeFind(new HibernateCallback() {
public Object doInHibernate(Session session) throws HibernateException {
Criteria criteria = getHibernateTemplate().createCriteria(session, MyClass.class);
...
return criteria.list();
}
});
Note that the createCriteria call on the template only serves to apply transaction timeout. In every other respect, this is equivalent to:
Code:
List result = getHibernateTemplate().executeFind(new HibernateCallback() {
public Object doInHibernate(Session session) throws HibernateException {
Criteria criteria = session.createCriteria(MyClass.class);
...
return criteria.list();
}
});
In general, if you need any Hibernate functionality that's not covered by HibernateTemplate's convenience operations, simply use a HibernateCallback, which gives you the full power of Hibernate's native API.
Juergen