I'm new and I have an assignment concerning JPA Criteria Queries. I'm trying to understand what exactly means this code.
EntityManager em = ...
CriteriaBuilder qb = em.getCriteriaBuilder();
CriteriaQuery<Person> c = qb.createQuery(Person.class);
Root<Person> p = c.from(Person.class);
Predicate condition = qb.gt(p.get(Person_.age), 20);
c.where(condition);
TypedQuery<Person> q = em.createQuery(c);
List<Person> result = q.getResultList();
Can you please explain every line in detail and why these are the steps to follow? I found many resources online but still I can't get the full figure of it...
For example what's the meaning of: createQuery(Person.class)
? Or the true difference between TypedQuery and a CriteriaQuery?
I've read what's the meaning of a query object from the blog of Martin Fowler: "A Query Object is an interpreter [Gang of Four], that is, a structure of objects that can form itself into a SQL query. You can create this query by refer-ring to classes and fields rather than tables and columns."
However it's written in a way that i still can't quite understand...
Thanks