Hi folks,
I'm using Hibernate 3.3.2.GA Entity Manager with JPA. My database is MySQL 5.0. I have an association between a Pricelist and a Product called ProductPrice. A straight-up Many-to-Many association wouldn't have given us the opportunity to add properties at the association point. (that I'm aware of) So, we have instead defined the two One-to-Many relationships. Here are some excerpts from the classes in question. (Note that Product has no knowledge of the ProductPrice entities that he participates in. This is by design.)
Product entity:
Code:
@Column(name="name", nullable=false, length=50)
private String name;
@Column(name="display_name", nullable=false, length=50)
private String displayName;
@Column(name="code", nullable=false, length=25)
private String code;
@ManyToOne
@JoinColumn(name="product_type_id")
private ProductType productType;
@ManyToOne
private Customer customer;
Pricelist entity:
Code:
@Column(name="name", nullable=false, length=50)
private String name;
@ManyToOne
private Customer customer;
@OneToMany(mappedBy="pricelist", cascade={CascadeType.ALL})
@JoinColumn(name="pricelist_id")
@org.hibernate.annotations.Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
private Set<ProductPrice> productPrices = new HashSet<ProductPrice>();
ProductPrice entity:
Code:
@ManyToOne(optional=false)
private Product product;
@ManyToOne(optional=false)
private Pricelist pricelist;
The problem - when I attempt to delete a Pricelist, I get a foreign key violation exception on the ProductPricelist entity. Other entities in my application that have a One-to-Many relationship are functioning properly and are defined in a way similar to the Pricelist->ProductPrice relationship. I can only assume that the problem stems from the other side of this Many-to-Many association.
Can anyone offer any possibilities?
Thanks,
Dave