|
Project Information
Members
Links
|
The JPA EntityManager is very powerful and for small projects it could be a replacemnt for a generic DAO. But most (CRUD) applications consists to 80% of simple queries like "give me the User with username X and all it's addresses". Or "give me all Users ordered by 'whatever'. In these simple cases it's better to create a generic query with parameters for restrictions, orders and fetches as instead of creating a query for every use case. In some cases e.g. a generic ui filter it's hardly possible to realize it with custom queryies for every filter case. The idea is partly taken from the book "Real World Java EE Patterns" which contains a "QueryParameter" class realized with the builder pattern usable in a fluent way. A common example: User item = genericDao.find(User.class,
QueryParameter.with(User_.username, "Andreas"),
QueryOrder.by(User_.username),
QueryFetch.withLeftJoin(User_.addresses));For Maven users: <dependency>
<groupId>it.bambo.common-jpa</groupId>
<artifactId>common-jpa</artifactId>
<version>1.1-SNAPSHOT</version>
</dependency>
<repositories>
<repository>
<id>bambo.it</id>
<url>http://artifactory.bambo.it:9090/repo</url>
</repository>
</repositories>
|