我有一个Category
类,看起来像这样:
@Entity
@Table(name = "categories")
public class Category implements Serializable {
// other attributes
@ManyToMany
@JoinTable(name = "articlecat",
joinColumns = {@JoinColumn(name = "categoryId")},
inverseJoinColumns = {@JoinColumn(name = "articleId")})
private List<Article> articleList;
// other methods
}
如何使用单个Categories
查询Article
,如下所示:
SELECT c FROM Category c WHERE c.articleList contains :article
答案 0 :(得分:2)
您可以使用MEMBER OF(OF是可选的)。
SELECT c FROM Category c WHERE :article MEMBER OF c.articleList