I have been reading that using HibernateDaoSupport isn’t a good idea, so I need some help on how to NOT use it 🙂
Old code:
public class GenericDaoImpl extends HibernateDaoSupport
implements GenericDao {
@Override
public T get(Class<T> type, K id) {
return super.getHibernateTemplate().get(type, id);
}
}
My Dao now looks like:
public class GenericDaoImpl<T, K extends Serializable> implements GenericDao<T, K> {
@Resource
private SessionFactory sessionFactory;
// @Override
public T get(Class<T> type, K id) {
return (T)sessionFactory.getCurrentSession().get(type, id);
//return super.getHibernateTemplate().get(type, id);
}
}
My spring.xml is now having issues setting the datasource since the property doesn’t exist in my GenericDaoImpl.
How do I set the datasource now?
<bean id="userDao" class="com.agilely.platform.services.UserServiceImpl">
<property name="dataSource" ref="dataSource"/>
</bean>
IntelliJ is complaining (and righly so) of the dataSource since there is no setter property.
How do I wireup the dataSource just like how the HibernateDaoSupport did it?
You supply the
DataSourceto theLocalSessionFactoryBean