title: JPA Specification filtering nested object
body: <p>I am trying to fetch nested object property but getting illegalArgument exception.</p>
  
  <pre><code>AuditTestingPlanSpecification name = new AuditTestingPlanSpecification(new SearchCriteria("auditPlanId.auditPlanEntity", ":",dates));
          Page&lt;AuditTestingPlanMaster&gt; a = auditTestingPlanMasterRepository.findAll(name, ten);
  </code></pre>
  
  <p>Please find below code,</p>
  
  <pre><code>public class AuditTestingPlanSpecification implements Specification&lt;AuditTestingPlanMaster&gt; {    
  private SearchCriteria criteria;
  
      public AuditTestingPlanSpecification(SearchCriteria searchCriteria) {
          this.criteria = searchCriteria;
      }
  
      @Override   
      public Predicate toPredicate(Root&lt;AuditTestingPlanMaster&gt; root, CriteriaQuery&lt;?&gt; query, CriteriaBuilder builder) {
  
          if (root.get(criteria.getKey()).getJavaType() == String.class) {
              return builder.like(root.&lt;String&gt;get(criteria.getKey()), "%" + criteria.getValue().get(0).toString() + "%");
          } else {
              return builder.equal(root.get(criteria.getKey()), criteria.getValue().get(0).toString());
          }
  
          return null;
      }
  }
  </code></pre>
  
  <p>Class SearchCriteria.java</p>
  
  <pre><code>public class SearchCriteria {
      public SearchCriteria(String key, String operation, List&lt;Object&gt; value) {
          super();
          this.key = key;
          this.operation = operation;
          this.value = value;
      }
      private String key;
      private String operation;
      private List&lt;Object&gt; value;
  
      // getters &amp; setters
  }
  </code></pre>
  
  <p>Class AuditTestingPlanMaster.java</p>
  
  <pre><code>@Entity
  @Table(name = "audit_testing_plan_master")
  @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
  public class AuditTestingPlanMaster implements Serializable {
  
      private static final long serialVersionUID = 1L;
      @Id
      @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
      @SequenceGenerator(name = "sequenceGenerator")
      private Long id;
  
      @Column(name = "risk_area_id")
      private Long riskAreaId;
  
      @Column(name = "expected_revert_date")
      private Instant expectedRevertDate;
  
      @Column(name = "created_date")
      private Instant createdDate;
  
      @Column(name = "last_modified_date")
      private Instant lastModifiedDate;
  
      @JoinColumn(name = "audit_plan_id", referencedColumnName = "id")
      private AuditPlanMaster auditPlanId;
  
  //getters &amp; setters
  }
  </code></pre>
  
  <p>Class AuditPlanMaster.java</p>
  
  <pre><code>@Entity
  @Table(name = "audit_plan_master")
  @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
  public class AuditPlanMaster implements Serializable {
  
      private static final long serialVersionUID = 1L;
      @Id
      @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
      @SequenceGenerator(name = "sequenceGenerator")
      private Long id;
  
      @Column(name = "remarks", length = 255)
      private String remarks;
  
      @Column(name = "audit_plan_entity", length = 50)
      private String auditPlanEntity;
  
      @Column(name = "start_date")
      private Instant startDate;
  
      @Column(name = "end_date")
      private Instant endDate;
  
      //getters &amp; setters
  
  }
  </code></pre>
  
  <p>I want to fetch all the AuditTestingPlanMaster objects whose AuditPlanMaster.auditPlanEntity string is matching with provided filter value. </p>
  
  <p>Thank you for your time and help in advance.</p>