Hi,
is there a way to have a one-to-many (e.g.) relationship more than once in a mapping?
The example below illustrates that I'd like to have two distinct collections each referencing the same class "Child" but collection maleChildren contains only a subset (as collection femalChildren does) of all 1:n children.
As I'd like to alter and persist both collections, a read-only mapping of one collection is not a solution.
The mapping in this example is not allowed and causes an exception.
Any ideas, hints are welcome!
//PSEUDOCODE
Tables:
PARENT (ID,NAME)
CHILDREN(ID,PARENT_ID,GENDER,NAME)
class Parent {
@Id
int id;
String name;
//
@OneToMany(mappedBy = "parent")
@Where("gender=0") ???
Collection<Child> maleChildren;
//second mapping is not allowed - any alternatives?
@OneToMany(mappedBy = "parent")
@Where("gender=1") ???
Collection<Child> femaleChildren
}
class Child{
static MALE_CHILD = 0;
static FEMALE_CHILD = 1;
int gender = 0;
@ID
int id;
@ManyToOne
@JoinColumn(name="parent_id",nullable=false)
Parent parent;
}
|