title: Hibernate Criteria One-to-Many Relationship
body: <p>I have two entities: <code>Dealers</code> and <code>Makes</code>. Dealers have multiple makes.I am able to insert the records as a one-to-many relationship between these two entities.</p>
  
  <p>However, I am not able to retrieve the records based on dealer ID. I tried many different ways and it's still throwing this exception: <code>Property not found make(it is table) of : class name(full classname)</code></p>
  
  <p>If anyone could provide me with some hints, it would be greatly appreciated.</p>
  
  <p>Dealer:</p>
  
  <pre><code> import java.util.HashSet;
      import java.util.Set;    
      import javax.persistence.Column;
      import javax.persistence.Entity;
      import javax.persistence.FetchType;
      import javax.persistence.GeneratedValue;
      import javax.persistence.Id;
      import javax.persistence.Table;
      import javax.persistence.OneToMany;
      import javax.persistence.JoinTable;
      import javax.persistence.CascadeType;
      import javax.persistence.JoinColumn;
      @Entity
      @Table(name = "dealer")
      public class Dealer implements java.io.Serializable{
          /**
           * 
           */
          private static final long serialVersionUID = 1L;
  
          public Dealer(){
  
          }
          public Dealer(String DealerName,String dealerPhno,Set makes){
              this.dealerName=DealerName;
              this.dealerphno=dealerPhno;
              this.dealerMakes=makes;
  
          }
          public void setDealerMakes(Set&lt;Make&gt; dealerMakes) {
              this.dealerMakes = dealerMakes;
          }
          @Id
          @GeneratedValue
          @Column(name = "dealer_id")
          private long dealerId;
          public long getDealerId() {
              return dealerId;
          }
          public void setDealerId(long dealerId) {
              this.dealerId = dealerId;
          }
          public String getDealerName() {
              return dealerName;
          }
          public void setDealerName(String dealerName) {
              this.dealerName = dealerName;
          }
          public String getDealerphno() {
              return dealerphno;
          }
          public void setDealerphno(String dealerphno) {
              this.dealerphno = dealerphno;
          }
          @Column(name = "dealer_name" ,unique=true, nullable = false, length=20)
          private String dealerName;
          @Column(name = "dealer_phno" , nullable = false, length=20)
          private String dealerphno;
          @OneToMany(cascade = CascadeType.ALL)
          //@OneToMany(fetch=FetchType.EAGER)
          @JoinColumn(name="dealer_id", nullable=false)
          //@JoinTable(name = "dealer_make", joinColumns = { @JoinColumn(name = "dealer_id") }, inverseJoinColumns = { @JoinColumn(name = "make_id") })
          private Set&lt;Make&gt; dealerMakes = new HashSet&lt;Make&gt;(0);
  
          public Set&lt;Make&gt; getDealerMakes() {
              return dealerMakes;
          }
  
      }
  </code></pre>
  
  <p><strong>Make</strong></p>
  
  <pre><code>import javax.persistence.Column;
  import javax.persistence.GeneratedValue;
  import javax.persistence.Id;
  import javax.persistence.Entity;
  import javax.persistence.Table;
  @Entity
  @Table(name = "make")
  public class Make implements java.io.Serializable {
  
      /**
       * 
       */
      private static final long serialVersionUID = 2L;
      public Make(){
  
      }
      public Make(String makeName,String modelName,String price){
  
          this.makeName=makeName;
          this.modelName=modelName;
          this.price=price;
      }
      public long getMakeId() {
          return makeId;
      }
      public void setMakeId(long makeId) {
          this.makeId = makeId;
      }
      public String getMakeName() {
          return makeName;
      }
      public void setMakeName(String makeName) {
          this.makeName = makeName;
      }
      public String getModelName() {
          return modelName;
      }
      public void setModelName(String modelName) {
          this.modelName = modelName;
      }
      public String getPrice() {
          return price;
      }
      public void setPrice(String price) {
          this.price = price;
      }
      @Id
      @GeneratedValue
      @Column(name = "make_id")
      private long makeId;
      @Column(name = "make_name" , nullable = false, length=8)
      private String makeName;
      @Column(name = "model_name" , nullable = false, length=8)
      private String modelName;
      @Column(name = "price" , nullable = false, length=8)
      private String price;
  
  }
  </code></pre>
  
  <p><strong>Query I tried:</strong></p>
  
  <pre><code> Criteria dealer=sessionFactory.getCurrentSession().createCriteria(Dealer.class);
   Criteria make=dealer.createCriteria(make);
   make.add(Restrictions.gt("dealerId",new Long(dealerId)));
   List&lt;Dealer&gt; results=dealer.list(); //throwing exception
  </code></pre>
  
  <p><strong>Ouput i am expecting:</strong></p>
  
  <p>Dealer_Id   dealername phonenumber</p>
  
  <p>1           halal      074563485</p>
  
  <p>Make has below records:</p>
  
  <p>make_id  makename  makeprice  dealer_id</p>
  
  <p>1         ford      3000$      1</p>
  
  <p>2         hyundai    2000$  1</p>
  
  <p>I want results like dealer details with make details.</p>