Hi, I'm new to Hibernate and I'm facing problem I can't find solution for.
I have two tables: price and discount and one association table - price_discount. Price and discount have many-to-many relation. Relation is defined in mapping classes like that:
in Price.java
Code:
@ManyToMany(
targetEntity=package.name.Discount.class))
@JoinTable(
name="price_discount",
joinColumns = @JoinColumn(name="priceid"),
inverseJoinColumns = @JoinColumn(name="discountid"))
public Set<Discount> getDiscounts() {
return discounts;
}
in Discount.java
Code:
@ManyToMany(mappedBy="discounts")
public Set<Price> getPrices() {
return prices;
}
What I want is to be able to remove price or discount with all records in association table (and only them). When I delete price, everything works fine, but when I try to delete discount, hibernate throws an exception that discount is still referenced in price_discount table. How can I define this relation to enable removing associations from both directions?