title: Hibernate: Unable to resolve attribute against path for a very simple object hierarchy
body: <p>Anyone have any ideas why hibernate v3.6.7 has problems with the seemingly simple class hierarchy below?</p>
  
  <pre><code>@Entity
  public class X implements Serializable {
      @Id
      String id;
  
      X() {
  
      }
  
      public X(String id) {
          this.id = id;
      }
  }
  
  interface PK {
      Object getPK();
  }
  
  @Entity
  public class Y  implements Serializable, PK {
      @Id
      @OneToOne
      @JoinColumn(name ="id")
      X x;
  
      protected Y() {
  
      }
  
      public Y(X x) {
          this.x = x;
      }
  
      @Override
      public Object getPK() {
          return x.id;
      }
  }
  
  private static final EntityManager em;
  private final CriteriaBuilder cb = em.getCriteriaBuilder();
  private final CriteriaQuery&lt;Y&gt; query = cb.createQuery(Y.class);
  private final Root&lt;Y&gt; entity = query.from(Y.class);
  
  static {
      Map&lt;String, Object&gt; properties = new HashMap&lt;String, Object&gt;();
          // initialise properties appropriately
      EntityManagerFactory emf =
          Persistence.createEntityManagerFactory("myPersistenceUnit", properties);
      em = emf.createEntityManager();
  
  }
  
  @Test
  public void simpleTest() {
      X x1 = new X("X1");
      X x2 = new X("X1");
      List&lt;Y&gt; yy = new ArrayList&lt;Y&gt;();
  
      Y yX1 = new Y(x1);
      yy.add(yX1);
  
      Y yX2 = new Y(x2);
      yy.add(yX2);
  
      saveItems(yy);
  
      String name = "x";
      Path&lt;Object&gt; path = entity.get(name);
      Predicate restriction = cb.conjunction();
      restriction = cb.and(restriction, cb.and(new Predicate[]{cb.equal(path, x1)}));
  
      TypedQuery&lt;Y&gt; tq = em.createQuery(this.query);
      Y result = null;
  
      try {
          result = tq.getSingleResult();
      } catch (NoResultException e) {
      }
  
      assertNotNull(result);
  }
  </code></pre>
  
  <p>attempting to execute this test throws the following exception:</p>
  
  <pre><code>java.lang.IllegalArgumentException: Unable to resolve attribute [x] against path
      at org.hibernate.ejb.criteria.path.AbstractPathImpl.unknownAttribute(AbstractPathImpl.java:118)
      at org.hibernate.ejb.criteria.path.AbstractPathImpl.locateAttribute(AbstractPathImpl.java:223)
      at org.hibernate.ejb.criteria.path.AbstractPathImpl.get(AbstractPathImpl.java:194)
      at com.example.entity.impl.MyPersistenceTest.simpleTest(MyPersistenceTest.java:212)
  </code></pre>