title: How to create a namedquery of manytomany entity?
body: <p><strong>Brand</strong></p>
  
  <pre><code>public class Brand implements Serializable {
      private static final long serialVersionUID = 1L;
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Basic(optional = false)
      @Column(name = "BrandID", nullable = false)
      private Integer brandID;
      @Basic(optional = false)
      @Column(name = "BrandName", nullable = false, length = 100)
      private String brandName;
      @Basic(optional = false)
      @Column(name = "Description", nullable = false, length = 1000)
      private String description;
      @Column(name = "Is_Visible")
      private Boolean isVisible;
      @JoinTable(name = "brandcategory", joinColumns = {
          @JoinColumn(name = "BrandID", referencedColumnName = "BrandID")}, inverseJoinColumns = {
          @JoinColumn(name = "CategoryID", referencedColumnName = "CategoryID")})
      @ManyToMany(fetch = FetchType.EAGER)
      private Collection&lt;Category&gt; categoryCollection;
      @OneToMany(mappedBy = "brand", fetch = FetchType.EAGER)
      private Collection&lt;Product&gt; productCollection;
  </code></pre>
  
  <p>I want to retrive the Brand IDs from table brandcategory whoes categoryID = :categoryID
  how can i createnamed query for it in entity brand?</p>
  
  <p><strong>this does not work:</strong></p>
  
  <pre><code>@NamedQuery(name = "Brand.getBrandListByCategory",
              query = "SELECT b FROM Brand b WHERE b.brandID =
              (SELECT bc.brandID
               FROM b.brandctegory bc
               WHERE bc.category.categoryID = :categoryID)")
  </code></pre>