Reputation: 619
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
Reputation: 42114
You can use MEMBER OF (OF is optional).
SELECT c FROM Category c WHERE :article MEMBER OF c.articleList
Upvotes: 2