EasyCriteria – New Functionalities

Hello, how are you?

I am here to talk about the new version of the EasyCriteria framework.

To those that are not familiar with EasyCriteria, EasyCriteria is a framework that makes easier the JPA Criteria utilization.


select p from Person p

It would be translated to the following JPA Criteria:

CriteriaQuery<Person> criteriaQuery = criteriaBuilder.createQuery(Person.class);
Root<Person> root = criteriaQuery.from(Person.class);
TypedQuery<Person> query = entityManager.createQuery(criteriaQuery);

That is a loot code to do a simple query. But, how do we solve this problem?

Just use the EasyCriteria framework. The query above could be executed like below:

EasyCriteria<Person> easyCriteria = EasyCriteriaFactory.createQueryCriteria(entityManager, Person.class);

With EasyCriteria is very easy to use JPA Criteria. Here are the EasyCriteria advantages:

  1. Allow JPA implementation portability: You could change your implementation to Hibernate, EclipseLink and OpenJPA without a problem.
  2. 100% test coverage test coverage
  3. Easy to use: EasyCriteria has the principle of exposing as little API as possible. The developer will use only the EasyCriteria interface.
  4. Good to be used by JPA rookies. Its methods are well detailed and documented.
  5. It can be found in the Maven repositories.

What is new in EasyCriteria?
The first this is the Criteria Transfer Object (CTO). Now it is possible to create an object in the view layer, without a EntityManager, to load all information related to the query to be executed in the database.
Check the code below to see how the CTO works:

public void controllerMethod(Integer id){
   EasyCriteria easyCTO = EasyCriteriaFactory.createEasyCTO();
   easyCTO.andEquals("id", id);

// and in the method
public void deactivateCar(EasyCriteria easyCTO){
    EasyCriteria<Car> easyCriteria = EasyCriteriaFactory.createQueryCriteria(entityManager, Car.class, easyCTO);
    Car car = easyCriteria.getSingleResult();

It is very simples to build your query at the same layer that has the parameters, and send it to the business layer execute it.

The other new functionality of this version is the LowerCase comparison:

boolean toLowerCase = true;

EasyCriteria<Person> easyCriteria = EasyCriteriaFactory.createQueryCriteria(getEntityManager(), Person.class);
easyCriteria.andEquals(toLowerCase, "name", "MARY");

The LowerCase was a functionality very requested by the framework users. If you want a functionality, just ask for it. [=

If you want to download the jar by the link, here is it:  https://code.google.com/p/easy-criteria/downloads/detail?name=EasyCriteria-2.2.2_2013-07-16.jar&can=1&q=#makechanges

If you want to use Maven to download it just add the dependency below:


I hope  that these new functions make your guys happy!

See you soon! o_

Leave a Comment