title: How to use Plural Attributes in JPA for criteria query?
body: <p>This is my root entity <code>ArticleType</code>  from which I want to generate a query. I want to fetch a collection <code>articleTypeVarianteOptionCollection</code> and add some condition for that collection.</p>
  
  <pre><code>public class ArticleType extends BaseEntity implements Serializable
  {
      private static final long                   serialVersionUID    = 1L;
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Basic(optional = false)
      @Column(name = "art_typ_index")
      private Integer                             artTypIndex;
      @Column(name = "art_typ_code", nullable = false)
      private String                              artTypCode;
      @OneToMany(mappedBy = "atvoIndexArticleType", fetch = FetchType.LAZY)
      private Set&lt;ArticleTypeVarianteOption&gt;      articleTypeVarianteOptionCollection;
  
      public Integer getArtTypIndex()
      {
          return artTypIndex;
      }
  
      public void setArtTypIndex(Integer artTypIndex)
      {
          this.artTypIndex = artTypIndex;
      }
  
  
      public String getArtTypCode()
      {
          return artTypCode;
      }
  
      public void setArtTypCode(String artTypCode)
      {
          this.artTypCode = artTypCode;
      }
  
  
      @XmlTransient
      public Set&lt;ArticleTypeVarianteOption&gt; getArticleTypeVarianteOptionCollection()
      {
          return articleTypeVarianteOptionCollection;
      }
  
      public void setArticleTypeVarianteOptionCollection(Set&lt;ArticleTypeVarianteOption&gt; articleTypeVarianteOptionCollection)
      {
          this.articleTypeVarianteOptionCollection = articleTypeVarianteOptionCollection;
      }
  
  
  }
  </code></pre>
  
  <p>This is my <code>OptionArticle</code> entity :</p>
  
  <pre><code>public class ArticleTypeOption extends BaseEntity implements Serializable {
      private static final long serialVersionUID = 1L;
      @Id 
        @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Basic(optional = false)
      @Column(name = "ato_index")
      private Integer atoIndex;
  
      @Column(name = "ato_isremoved")
      private Integer atoIsremoved;
      @JoinColumn(name = "ato_index_art_type", referencedColumnName = "art_typ_index")
      @ManyToOne(fetch = FetchType.LAZY)
      private ArticleType atoIndexArtType;
      @JoinColumn(name = "ato_index_option", referencedColumnName = "opt_art_index")
      @ManyToOne(fetch = FetchType.LAZY)
      private OptionArticle atoIndexOption;
  
      public ArticleTypeOption() {
      }
  
      public ArticleTypeOption(Integer atoIndex) {
          this.atoIndex = atoIndex;
      }
  
      public Integer getAtoIndex() {
          return atoIndex;
      }
  
      public void setAtoIndex(Integer atoIndex) {
          this.atoIndex = atoIndex;
      }
  
  
      public Integer getAtoIsremoved() {
          return atoIsremoved;
      }
  
      public void setAtoIsremoved(Integer atoIsremoved) {
          this.atoIsremoved = atoIsremoved;
      }
  
      public ArticleType getAtoIndexArtType() {
          return atoIndexArtType;
      }
  
      public void setAtoIndexArtType(ArticleType atoIndexArtType) {
          this.atoIndexArtType = atoIndexArtType;
      }
  
      public OptionArticle getAtoIndexOption() {
          return atoIndexOption;
      }
  
      public void setAtoIndexOption(OptionArticle atoIndexOption) {
          this.atoIndexOption = atoIndexOption;
      }
  }
  </code></pre>
  
  <p>My query would be :</p>
  
  <pre><code>SELECT 
  articleType
  FROM ArticleType articleType 
  LEFT JOIN articleType.articleTypeVarianteOptionCollection atOption
  where atOption.atoIsremoved = 0;
  </code></pre>
  
  <p>I have tried this for where clause in jpa :-</p>
  
  <pre><code>CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
  CriteriaQuery&lt;T&gt; criteriaQry = criteriaBuilder.createQuery(entityClass);
  Root&lt;T&gt; root = criteriaQry.from(entityClass);
  criteriaQry.select(root).distinct(true);
  
  for (PluralAttribute&lt;? super T, ?, ?&gt; pa : root.getModel().getPluralAttributes())
  {
      System.out.println(pa.getName());
      System.out.println(pa.getCollectionType());
  }
  </code></pre>
  
  <p>Now how to add where clause using this PluralAttribute ?<br>
  Thanks in advance.</p>