API criteria correlate

I was Google, but I don’t understand how the result of calling the method correlates javax.persistence.criteria.Subquery in the criteria API.

http://www.objectdb.com/api/java/jpa/criteria/Subquery/correlate_CollectionJoin_

This is from the Pro JPA2 Java Mastering Persistence API book.

When creating the definition of the API criteria request for this request, we must correlate the attribute of Project employees and then attach it to direct reports to calculate the average wage. This example also demonstrates the use of the type () method of the interface path to conduct polymorphic type comparisons:

CriteriaQuery<Project> c = cb.createQuery(Project.class);
Root<Project> project = c.from(Project.class);
Join<Project,Employee> emp = project.join("employees");
Subquery<Number> sq = c.subquery(Number.class);
Join<Project,Employee> sqEmp = sq.correlate(emp);
Join<Employee,Employee> directs = sqEmp.join("directs");
c.select(project)
 .where(cb.equal(project.type(), DesignProject.class),
        cb.isNotEmpty(emp.<Collection>get("directs")),
        cb.ge(sq, cb.parameter(Number.class, "value")));

What does this line do?
Join sqEmp = sq.correlate (emp);

+5
source share
1 answer

, ,

+7

All Articles