Hi everybody,
I need a many-to-many mapping with one side sorted by index. Sounds simple, but every example I found either went off on a much too complex tangent or ended unfinished.
Basically, I have Parent objects with a list of Children and Child objects with a set of parents. I want to manipulate the list and I want Hibernate to care about the connecting table and the order number.
I found solutions for children with only one parent, but my children have multiple parents and of course a different list position for each parent.
I found solutions for intermediate objects (ParentToChild with parentId, childId, orderNo and various other data), but I don't want a List <ParentToChild>, I want a List<Child>.
Is this possible and how would I have to annotate the methods?
Code:
@Entity
@Table(name="parent")
public class Parent {
private int id;
private List<Child> children = new ArrayList<Child>();
public List<Child> getChildren() {
return children;
}
public void setChildren(List<Child> children) {
this.children = children;
}
}
@Entity
@Table(name="child")
public class Child {
private int id;
private Set<Parent> parents = new HashSet<Parent>();
public Set<Parent> getParents() {
return parents;
}
public void setParents(Set<Parent> parents) {
this.parents = parents;
}
}
Regards, Georg