title: JPA - How to query using Specification and @EmbeddedId?
body: <p>I'm using a JPA query that uses a specification to retrieve entities. When I execute the query, I'm getting the error:</p>
  
  <blockquote>
    <p>org.springframework.data.mapping.PropertyReferenceException: No property name found for type Task!</p>
  </blockquote>
  
  <p>I've looked at the answers to similar questions that have been asked on this site previously &amp; tried to model my code to follow the patterns that were recommended but the code is still failing.</p>
  
  <p>When I step through the code with a debugger, the expanded path in the criteria builder is returning the embedded ID class, but when the specification is actually used in the query it looks like the attribute is being applied to the base entity class.</p>
  
  <p>Am I missing something obvious?</p>
  
  <p>Here is the entity class:</p>
  
  <pre><code>@Entity
  @Table(name = "TASKS")
  public class Task implements Serializable {
  
      @EmbeddedId
      private TaskId id;
  
      ...more attributes, getters and setters
  }
  </code></pre>
  
  <p>Here is the embedded ID entity class:</p>
  
  <pre><code>@Embeddable
  public class TaskId implements Serializable {
  
      @Column(name = "NAME", length = 100)
      private String name;
  
      ...more attributes, getters and setters
  }
  </code></pre>
  
  <p>Here is the specification builder that matches on the embedded id 'name' attribute:</p>
  
  <pre><code>public class HasTaskNameSpec {
  
      private HasTaskNameSpec() {
      }
  
      public static Specification&lt;Task&gt; equals(String name) {
          return (root, query, criteriaBuilder) -&gt; {
              return criteriaBuilder.equal(root.get("id").get("name"), taskName);
          };
      }
  
  }
  </code></pre>
  
  <p>The query is executed on the repository as follows:</p>
  
  <pre><code>List&lt;Task&gt; results = taskRepository.findAll(HasTaskNameSpec.equals("foo"));
  </code></pre>
  
  <p>The repository itself is very simple:</p>
  
  <pre><code>public interface TaskRepository extends JpaRepository&lt;Task, TaskId&gt;, JpaSpecificationExecutor&lt;Task&gt; {
     List&lt;Task&gt; findByIdName(String name);
     Page&lt;Task&gt; findByIdName(String name, Pageable page);    
  }
  </code></pre>
  
  <p>** <strong>EDIT</strong> added methods to repository as was suggested below **</p>