title: Hibernate double level criteria
body: <p>I have 2 classes.</p>
  
  <p>Occupation.class</p>
  
  <pre><code>@Entity
  @Table(name = "occupazione")
  public class Occupazione implements java.io.Serializable {
  
      /**
       * omitted the fields for brevity
       */
  
      private int idOccupation;
      private Posto posto;
  
  @ManyToOne
      @JoinColumn(name = "id_posto")
      public Posto getPosto() {
          return this.posto;
      }
  
      public void setPosto(Posto posto) {
          this.posto = posto;
      }
  </code></pre>
  
  <p>And Posto.class</p>
  
  <pre><code>@Entity
  @Table(name = "posti")
  @JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="idPosto")
  public class Posto implements java.io.Serializable {
  
      /**
       * 
       */
      private static final long serialVersionUID = 1L;
      private int idPosto;
      private Piano piano;
  
  
      @ManyToOne
      @JoinColumn(name="id_piano")
      @JsonIgnore
      public Piano getPiano() {
          return piano;
      }
  
      public void setPiano(Piano piano) {
          this.piano = piano;
      }
  </code></pre>
  
  <p>Now, i want to retrieve all Occupation objects for a given Piano</p>
  
  <p>I was doing this way</p>
  
  <pre><code>Criteria criteria = sess.getSession().createCriteria(Occupation.class).
                              createCriteria("posto").
          add(Restrictions.eq("piano", piano));
  
          return criteria.list();
  </code></pre>
  
  <p>but I'm getting this exception</p>
  
  <pre><code>org.hibernate.QueryException: could not resolve property: posto of: it.besmart.models.Posto
  </code></pre>
  
  <p>But it's strange because <code>posto</code> should be referred to Occupation, not Posto itself...</p>