Announcement Announcement Module
Collapse
No announcement yet.
Forming a QueryDSL Predicate through a OneToMany join Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Forming a QueryDSL Predicate through a OneToMany join

    I'm having difficulty determining the right way to write a Predicate with QueryDSL and Spring Data JPA.

    Take the following Data model:
    Code:
    public class Company {
    @OneToMany
    private Set<Employee> emps;
    }
    
    public class Employee {
    @ManyToOne
    private Division division;
    }
    
    public class Division {
    private String name;
    }
    I want the Predicate to evaluate to true for companies that have employees in the Research division, so I create the following class:

    Code:
    public class CompanyPredicates {
    
      public static Predicate hasResearchEmployees {
        return QCompany.company.emps.???.division.name.eq("Research");
      }
    This code would be called using:
    Code:
    List<Company> companies = CompanyRepository.findAll(hasResearchEmployees());
    Can somebody help me fill in the question marks in the hasResearchEmployees method?

  • #2
    Terribly late with the answer, but I guess the missing piece is any().

    Comment

    Working...
    X