Hi all,
I'll preface this with the fact that I'm new to Hibernate, but alas, I have been unable to find the answer to solve my problem while searching the docs, forums, and plenty of results returned by Google for the past couple days.
Here's the general class structure idea (with the fluff removed):
Code:
@Entity
@Table(name = "composite_item")
public class CompositeItem extends DomainModelObject {
@CollectionOfElements
@JoinTable(name = "composite_item_has_part", joinColumns = @JoinColumn(name = "parent_id"))
@MapKeyManyToMany(joinColumns = @JoinColumn(name = "child_id"))
@Column(name = "quantity")
private Map<CompositeItem, Double> parts;
@ManyToMany(mappedBy="parts")
private List<CompositeItem> parents;
}
This code worked just fine up to the point where I added the "parents" field to the class. At that point, I struggled with having the field properly mapped to the database. I've tried a bunch of different annotations, but none have been successful.
The basic idea is that I'd like to get the "parts" and "parents" fields mapped using one table to map the associations along with the quantity in the "parts" map. Having the bidirectional association is important for the parts of the current system's domain logic to function correctly.