A Ebean like finder for JPA 1

Posted by Jens J├Ąger on December 29, 2013

After the decision to go for JPA instead of Ebean with a Play Framework project, the first problem to solve was a replacement for the ebean finder.

The project team started with these simple requirements:

  • Jpa based
  • Easy to use
  • Can return a finder object, to add restrictions outside of the model (Used for generic components like the sort function of a data table view)

After some prototyping with different implementations, we found this gist and decided to start from there with Hibernate Criteria.

You can find the results in the query package and the generic model of my Play4Jpa project. The GenericModel doesn’t contain a generated long based @Id. You should only extend from GenericModel when you use combined keys. If you need a long based @Id you can extend from Model.

To get a query object from a Object that extends Model. You just have to add the method:

To find all Tasks with the query you just need to add the following findAll Method:

Here is a example of a simple where condition:

Trackbacks

Use this link to trackback from your own site.

Comments

Leave a response

  1. Join example for JPA finder - jensjaeger.com Tue, 31 Dec 2013 14:56:26 CET

    […] JPA finder for play 2 works with joins as […]

Comments

Information about Data protection