I'm developing my first app with JPA/Hibernate and Spring. My first attempt at a DAO class looks like this:
@Repository(value = "userDao")
public class UserDaoJpa implements UserDao {
@PersistenceContext
private EntityManager em;
public User getUser(Long id) {
return em.find(User.class, id);
}
public List getUsers() {
Query query = em.createQuery("select e from User e");
return query.getResultList();
}
}
I also found some examples using JpaDaoSupport
and JpaTemplate
. Which design do you prefer? Is there anything wrong with my example?