title: Filtering a collection using the @Filter hibernate annotation in java
body: <p>I have two hibernate mapped entities A and B.  </p>
  
  <p>A has 2 collections of entity B and I would like to filter each collection based on a property held in B (as shown in code below).</p>
  
  <pre><code>@FilterDefs()
  class A{
  
  @OneToMany(mappedBy = "productType", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
  @Filter(name = "something", condition = "entityType = 'SKU1'")  
  Set&lt;B&gt; set1 = new HashSet&lt;B&gt;();
  
  @OneToMany(mappedBy = "productType", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
  @Filter(name = "something", condition = "entityType = 'SKU2'")  
  Set&lt;B&gt; set2 = new HashSet&lt;B&gt;();
  
   }
  
  class B{
  
  @ManyToOne(cascade = CascadeType.ALL)
  private A productType;
  
  @Column(name = "entity_type")
  @Enumerated(EnumType.STRING)
  private EntityType entityType;
  }
  </code></pre>
  
  <p>Edited:
  I am enabling the filters as suggested below in my DAO method.  However, I am getting the following exception</p>
  
  <blockquote>
    <p>org.hibernate.exception.SQLGrammarException: could not initialize a
    collection</p>
  </blockquote>
  
  <p>If i use the eager loading method, I am getting an exception to do with invalid SQL getting generated?</p>
  
  <p>Any pointers?</p>