Hello,
I'm using Spring with Struts and Hibernate. I have setup the openSessionInView filter to user lazy loading.
I'm asking if I should use HibernateCallback in my DAO methods.
For example :
Without using a callback, the code is cleaner :Code:Integer count = (Integer) getHibernateTemplate().execute ( new HibernateCallback() { public Object doInHibernate( Session session ) throws HibernateException { Criteria criteria = session.createCriteria( Product.class ); criteria.add( Restrictions.like("name", productName) ); criteria.setProjection( Projections.rowCount() ); return criteria.uniqueResult(); } } );
(getSession() comes from the inherited HibernateDaoSupport)Code:Criteria criteria = getSession().createCriteria( Product.class ); criteria.add( Restrictions.like("name", productName) ); criteria.setProjection( Projections.rowCount() ); Integer count = (Integer) criteria.uniqueResult();
In fact, with CallBack, I'm just writing more code and this doesn't seem of any use with the OpenSessionInView filter.
So should I write wallback code or just use getSession() ?
Thanks,
Thomas


Reply With Quote
