Apply filter on linking table in Hibernate

Viewed 2295

enter image description here

I've got a classic case of Category <-> Category_Product <-> Product relation. CategoryDTO class has Set<ProductDTO> member that defined as:

@ManyToMany(cascade = CascadeType.ALL)
@JoinTable(
        name = "Category_Product",
        joinColumns = @JoinColumn(name = "CAT_ID"),
        inverseJoinColumns = @JoinColumn(name = "PROD_ID")
)
public Set<Product> getProducts() {
    return products;
}

The problem is that I want to have Category->Product relation if and only if the Category_Product.ENABLED is '1'. I tried to use @FilterJoinTable annotation but, as I understand, it works on entities only (not on linking table), so it doesn't help here. I hope that there is an elegant solution that uses Hibernate built-in features.

1 Answers
Related