I am trying to follow the advice of Craig Wells, in the Spring in Action book in order to create a Springless DAO to utilize hibernate aka hibernate contextual sessions.
I started with the following.
I wanted to change it toCode:protected HibernateTemplate hibernateTemplate= null; @Autowired public void setSessionFactory(SessionFactory sessionFactory) { hibernateTemplate = new HibernateTemplate(sessionFactory); } @Override @SuppressWarnings("unchecked") public Collection<Asset> findAssets() throws DataAccessException { return hibernateTemplate.find("from Asset"); }
It works, however I am noticing that getCurrentSession returns a "classic" session and most of the needed methods there like find() are deprecated. What is the recommended approach such that I retrieve a non "classic" Session.Code:protected SessionFactory sessionFactory= null; @Autowired public void setSessionFactory(SessionFactory sessionFactory) { this.sessionFactory = sessionFactory; } @Override @SuppressWarnings("unchecked") public Collection<Asset> findAssets() throws DataAccessException { return sessionFactory.getCurrentSession().find("from Asset"); }
I am using Hibernate 3.6 and Spring 3.06


Reply With Quote