hari
hari

Reputation: 619

List inside a JPQL query

I have a Category class which looks like this:

@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
 }

How can I query Categories using a single Article, something like this:

SELECT c FROM Category c WHERE c.articleList contains :article

Upvotes: 1

Views: 229

Answers (1)

Mikko Maunu
Mikko Maunu

Reputation: 42114

You can use MEMBER OF (OF is optional).

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

Upvotes: 2

Related Questions