在JPQL查询中列出

时间:2011-12-13 15:12:38

标签: java list jpa jpql

我有一个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

1 个答案:

答案 0 :(得分:2)

您可以使用MEMBER OF(OF是可选的)。

SELECT c FROM Category c WHERE :article MEMBER OF c.articleList