Have you ever needed to do a runtime Query with JPA? Imagine the JPQL below:

SELECT P 
FROM PERSON P
WHERE P.NAME = 'JOSEPH'

If you want to use JPA Criteria, your code would look something like:

final CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
final CriteriaQuery<Person> criteriaQuery = criteriaBuilder.createQuery(Person.class);
final Root<Person> root = criteriaQuery.from(Person.class);
criteriaQuery.select(root);
// the code above it is just to do a select p from Person p

final Path name = root.get("name");
final Predicate predicate = criteriaBuilder.equal(name, "Joseph");
criteriaQuery.where(predicate);
// now we created the where condition

final TypedQuery<Person> typedQuery = entityManager.createQuery(criteriaQuery);
final List<Person> resultList = typedQuery.getResultList();
// after 10 lines, we have the query result

We needed all that code to do a simple JPQL. How can we get a better code?

Take a look at the code below:

final UaiCriteria uaiCriteria = UaiCriteriaFactory.createQueryCriteria(entityManager, Person.class);
uaiCriteria.andEquals("name", "Josehp");
final List uaiCriteriaResult = uaiCriteria.getResultList();

We reduced from 9 lines to 3, now our code is easier to read and without all Criteria verbosity.