Is there any good generic JPA DAO implemenation?

被刻印的时光 ゝ 提交于 2019-12-07 04:38:15

问题


According this article, generic JPA DAO(Data Access Object) is a pretty nice pattern.

Is there any good implementation?


回答1:


You could take a look into the Spring Data JPA.

A few new concepts were introduced into Spring Data JPA, for instance the Query creation based on the method name, so you can declare a method like findById(String id) and the "generic" implementation will interpret the method's name and execute something like select Entity from Entity where id = 'given string'

Methods like findByNameAndLastName(String name, String lastName) or even findByNameOrInternalId(String name, int internalId) are supported too.




回答2:


Just wanted to mention a couple more generic dao implementations for JPA:

  • Generic DAO toolkit - http://code.google.com/p/generic-dao/
  • Related Question in SO - Single DAO & generic CRUD methods (JPA/Hibernate + Spring)
  • A good blog article on JPA DAO - http://blog.xebia.com/2009/03/09/jpa-implementation-patterns-data-access-objects/



回答3:


Querydsl supports JPA and has an extensive support for building complex predicates for queries.

It doesn't support updates and inserts but you can use Spring Data for that, as Querydsl also integrates with Spring repositories.



来源:https://stackoverflow.com/questions/11058972/is-there-any-good-generic-jpa-dao-implemenation

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!