title: hql query for one to many relationship
body: <p>This my Category Entity   </p>
  
  <pre><code>@Entity
  public class Category {
  
  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  private int id;
  
  @OneToMany(mappedBy = "category",cascade = CascadeType.ALL)
  List&lt;Product&gt;product;
  
  public Category(){
  
  }
  
  
  public Category(int id){
  
      this.id=id;
  }
  
  public Category(String name){
      this.name=name;
  }
  public int getId() {
      return id;
  }
  
  public void setId(int id) {
      this.id = id;
  }
  
  public List&lt;Product&gt; getProduct() {
      return product;
  }
  
  public void setProduct(List&lt;Product&gt; product) {
      this.product = product;
  }
  
  
  private String name;
  
  public String getName() {
      return name;
  }
  
  public void setName(String name) {
      this.name = name;
   }
  
  }
  </code></pre>
  
  <p>And this is my Product entity</p>
  
  <pre><code>@Entity
  public class Product implements java.io.Serializable  {
  
  @ManyToOne(fetch = FetchType.EAGER)
  private Category category;
  
  public Category getCategory() {
      return category;
  }
  
  public void setCategory(Category category) {
      this.category = category;
  }
  
  
  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  private int productId;
  
  public int getProductId() {
      return productId;
  }
  
  public void setProductId(int productId) {
      this.productId = productId;
  }
  
  
  @NotEmpty
  private String name;
  @NotEmpty
  private int price;
  
  
  
  public String getName() {
      return name;
  }
  
  public void setName(String name) {
      this.name = name;
  }
  
   public int getPrice() {
      return price;
   }
  
  public void setPrice(int price) {
      this.price = price;
   }
  
   }
  </code></pre>
  
  <p>Now you can see that there is one to many relatonship between category and product.I want to fetch a category with a product id. i wrote a query like </p>
  
  <pre><code> Category c=(Category)session.createQuery("from Category c where    c.product.productId=:productId").setParameter("productId",id).list().get(0);
  </code></pre>
  
  <p>but this query is not working.what did i do wrong in the code.?</p>