Results 1 to 2 of 2

Thread: Forming a QueryDSL Predicate through a OneToMany join

  1. #1
    Join Date
    Aug 2010
    Posts
    5

    Default 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. #2
    Join Date
    Aug 2011
    Posts
    8

    Default

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •