Question: I am upgrading my project from **spring 3.0.5 & hibernate 3** to **spring 3.1.1 & hibernate 4.1**

I use **org.springframework.orm.hibernate3.support.HibernateDaoSupport** extensively. In concrete **HibernateTemplate**; like in this snippet:

```
public class MenuDaoImpl extends HibernateDaoSupport implements MenuDao, Serializable {

public List<Menu> getMenus() {
    return getHibernateTemplate().find("from Menu menu");
}

//etc

}

```

But I read that HibernateTemplate **isn't recommended for use anymore**.

So, what’s the recommended way to hit the database within the DAO's in Spring3.1.1?

Thanks

Answer: 
Inject an EntityManager and use it directly.

```
public class MenuDaoImpl implements MenuDao {

@PersistenceContext
private EntityManager entityManager;

...

}

```

Here's a [good example on the SpringSource blog](http://blog.springsource.org/2006/08/07/using-jpa-in-spring-without-referencing-spring/).
As of Hibernate 3.0.1, Spring recommends the use of `SessionFactory`, rather than the `HibernateTemplate`.

From the [Spring 3.0 HibernateTemplate API docs](http://static.springsource.org/spring/docs/3.0.x/javadoc-api/):

> 
> NOTE: As of Hibernate 3.0.1, transactional Hibernate access code can
>  also be coded in plain Hibernate style. Hence, for newly started
>  projects, consider adopting the standard Hibernate3 style of coding
>  data access objects instead, based on
>  SessionFactory.getCurrentSession().
> 
> 
> 

Example:

```
public class MenuDao {

    @Autowired
    private SessionFactory sessionFactory;

    public List<Menu> getMenus() {
        return (List<Menu>) sessionFactory.getCurrentSession.createQuery("from Menu").list();
    }
}

```