This is my code, which I can't even compile:
/**
* Find a project that has NO employee assigned yet.
*/
public Project findEmptyProject() {
// getting criteria builder
CriteriaBuilder cb = this.em.getCriteriaBuilder();
// gathering meta information about left-joined entity
Metamodel m = this.em.getMetamodel();
EntityType<Employee> Employee_ = m.entity(Employee.class);
// creating query
CriteriaQuery<Project> cq = cb.createQuery(Project.class);
// setting query root for the query
Root<Project> project = cq.from(Project.class);
// left-joining with another employees
Join<Employee, Project> projects = project.join(
Employee_.project,
JoinType.LEFT
);
// instructing the query to select only projects
// where we have NO employees
cq.select(project).where(Employee_.id.isNull());
// fetching real data from the database
return this.em.createQuery(cq).getSingleResult();
}
My model classes are:
public class Employee {
@Id private Integer id;
@ManyToOne private Project project;
private String name;
}
public class Project {
@Id private Integer id;
private String name;
}
Compiler says (and I would say the same being a compiler):
Finder.java: cannot find symbol: variable project
location: interface javax.persistence.metamodel.EntityType<com.XXX.Employee>
What am I doing wrong?