I have a parent object that can have two different types of children (call them Red children and Blue children). My object model looks something like the following:
Code:
public class Parent {
public long getId();
public void setId();
public List getRedChildren();
public void setRedChildren(List c);
public List getBlueChildren();
public void setBlueChildren(List c);
// ...
};
public class Child {
public long getId();
public void setId(long n);
// ...
};
Underneath, these object model needs to map onto the following table structure:
Code:
CREATE TABLE Parent(
id NUMBER(14) NOT NULL PRIMARY KEY,
...
);
CREATE TABLE Child(
id NUMBER(14) NOT NULL PRIMARY KEY
...
);
CREATE TABLE ParentChildMap(
parent_id NUMBER(14),
child_id NUMBER(14),
child_type VARCHAR(1)
);
where the child_type column on ParentChildMap determines whether the child is blue or red ('B' for blue, 'R' for red). I'm trying to create a read/write mapping for this object model on to this table model. I know I can use a where clause on my many-to-many mapping for redChildren and blueChildren to only select the rows that have the appropriate child_type. But I'm trying to make this a read/write mapping, such that when I persist a parent that contains Red children, an entry is created in the ParentChildMap table with the appropriate child_type value. I've gone through the docs and the forums, but haven't found a way to achieve this. Can this be accomplished through the mapping file?
Thanks in advance.