ブランド
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<Category> categoryCollection;
@OneToMany(mappedBy = "brand", fetch = FetchType.EAGER)
private Collection<Product> productCollection;
テーブル brandcategory whoes categoryID = :categoryID からブランド ID を取得したいのですが、エンティティ ブランドで名前付きクエリを作成するにはどうすればよいですか?
これは動作しません:
@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)")