Announcement Announcement Module
Collapse
No announcement yet.
Creating Springless Hibernate DAO Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Creating Springless Hibernate DAO

    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.
    Code:
    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");
    
    
        }
    I wanted to change it to

    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");
    
    
        }
    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.

    I am using Hibernate 3.6 and Spring 3.06
Working...
X