spring - JPA and DAO - what's the standard approach? -


i'm developing first app jpa/hibernate , spring. first attempt @ dao class looks 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 user e");         return query.getresultlist();     } } 

i found examples using jpadaosupport , jpatemplate. design prefer? there wrong example?

i'd approach looks totally sound. don't use jpadaosupport or jpatemplate because can need entitymanager , criteria queries.

quote javadoc of jpatemplate:

jpatemplate exists sibling of jdotemplate , hibernatetemplate, offering same style people used it. newly started projects, consider adopting standard jpa style of coding data access objects instead, based on "shared entitymanager" reference injected via spring bean definition or jpa persistencecontext annotation.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -