Why is Criteria API .not() not functioning?

Viewed 18

If i leave out the .not() it gives me back the Projects having Events like it should. Now i would expect it to return the Projects without Events if i add the .not() but it just returns nothing.

Function:

public List<Project> findAllWithoutEvents(ProjectFilter filter) {
    Session session = sessionFactory.openSession();
    CriteriaBuilder cb = session.getCriteriaBuilder();
    CriteriaQuery<Project> cr = cb.createQuery(Project.class);
    Root<Project> fromProject = cr.from(Project.class);


    cr.select(fromProject).where(fromProject.get("id").in(fromProject.joinList("events").join("project").get("id")).not());
    Query<Project> query = session.createQuery(cr);

    return query.getResultList().stream().distinct().collect(Collectors.toList());
}

Project Class has a OneToMany <-> ManyToOne Relation with Event Class

0 Answers
Related