Pos Graduation : MIT Software Engineering – Java (Infnet College) Developer Experience: 10+ years on systems developments 7+ years as Delphi developer 3+ years as Java developer 8+ months as Java teacher Agile, Scrum, TDD SQLServer, Oracle, Postgres, MySQL Java Certifications: SCJP (1.6) SCWCD (1.5) OCBCD In Progress Hebert is a DZone MVB and is not an employee of DZone and has posted 7 posts at DZone. You can read more from them at their website. View Full User Profile

EasyCriteria 1.0 Released

  • submit to reddit

EasyCriteria is an open source tool to make the JPA Criteria code for any kind of JPA implementation easier . EasyCriteria has 100% of coverage on its tests with JUnit and it is tested with Hibernate, OpenJPA and EclipseLink.

If you want to understand the Criteria ideal and how to apply it to your code check this post: EasyCriteria – An easy way to use the JPA Criteria

The new EasyCriteria functionality includes:

  • Join with conditions
  • Query Pagination

Now it is possible to do a Join and add parameters to it:

EntityManager em = emf.createEntityManager();
EasyCriteria<Person> easyCriteria = EasyCriteriaFactory.createQueryCriteria(em, Person.class);
easyCriteria.innerJoin("dogs", Dog.class);
easyCriteria.whereJoinEquals("dogs", "name", "Dark");
easyCriteria.whereJoinStringNotIn("dogs", "name", names); // names is a List<String>
easyCriteria.whereJoinStringLike("dogs", "name", "M%");
easyCriteria.whereJoinListIsEmpty("dogs", "cars");
easyCriteria.whereJoinAttributeIsNull("dogs", "nickName");
easyCriteria.whereJoinStringBetween("dogs", "name", "A", "L");

The query can be paginated:

EasyCriteria<Dog> eascyCriteria = EasyCriteriaFactory.createQueryCriteria(getEntityManager(), Dog.class);

This new version also has 100% of code coverage.

Click here to download the code of this post with EasyCriteria. With this code you can test EasyCriteria as you like.

In the project page (http://easycriteria.uaihebert.com/) you will find all documentation.

If you have any doubt, just post it.





Published at DZone with permission of Hebert Coelho De Oliveira, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)


Balint Persics replied on Mon, 2012/08/13 - 4:52am

I think a Builder Pattern or some overloaded methods could be better.





And I miss the API docs.

Besides of that, I think this is a very useful project, the API for JPA Criteria is not expressive. 

Hebert Coelho replied on Tue, 2012/08/14 - 11:13am

Hello Balint Persics,


You can do easyCriteria.setFirstResult(0).setMaxResults(5); without a problem.


Thanks for the suggestion.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.