Hi,
I am implementing an Hibernate 3.0/Spring 1.2 RC1 solution. This solution will run on a WAS 4.0.6 running under IBMJRE 1.3.1.
I would like to know what is the "best" implementation of Hibernate inside Spring. What are the pro/con of the two options : the Hibernate Template way or AOP Interceptor way.
In the Spring 1.2 RC1 PDF, it says that the major advantage is to "allow any checked application exception to be thrown within the data access code...". I am not sure I understand that. Hibernate 3.0 should throws only (?) unchecked exceptions... so does it mean that I should use Hibernate Template instead of AOP Interceptor, because there is no real benefits?
Also, this data layer will need to provide good performance. I heard that the Spring AOP can put some overhead... is that true?
Here the chapter of the chapter 11.2.4 of Spring 1.2RC1 doc (page 111):
This exemple provided by the Spring doc is based on Hibernate 2:The major advantage of
HibernateInterceptor is that it allows any checked application exception to be thrown within the data access
code, while HibernateTemplate is restricted to unchecked exceptions within the callback. Note that one can
often defer the respective checks and throwing of application exceptions to after the callback, though. The
interceptor's major drawback is that it requires special setup in the context. HibernateTemplate's convenience
methods offers simpler means for many scenarios.
Code:public class ProductDaoImpl extends HibernateDaoSupport implements ProductDao { public List loadProductsByCategory(final String category) throws MyException { Session session = SessionFactoryUtils.getSession(getSessionFactory(), false); try { List result = session.find("from test.Product product where product.category=?", category, Hibernate.STRING); if (result == null) {throw new MyException("invalid search result");} return result; }catch (HibernateException ex) { throw SessionFactoryUtils.convertHibernateAccessException(ex); } } }
Does it mean I should go for the Hibernate Template implementation?
Thanks for your inputs!
Etienne
Montreal


Reply With Quote