One to One
One of the more unusual relationships is a one-to-one relationship. In these relationships there is generally no clear-cut "child" object or "parent" object; there is more of a peer relationship. For the sake of clarity, we will continue to use the parent and child objects defined above. In this situation, the parent methods would be as follows:
/** * @ejb.interface-method * * @ejb.relation name="Parent-to-Child" * role-name="Parent-has-one-Child" * target-ejb="ExampleChildBean" * target-role-name="Child-has-one-parent" * * @jboss.relation fk-column="parentID" * related-pk-field="ID" * * @return */ public abstract ExampleChildLocal getChild(); /** * @ejb.interface-method */ public abstract void setChild(ExampleChildLocal c);
The child methods would be nearly identical to the parent methods:
/** * @ejb.interface-method * * @ejb.relation name="Parent-to-Child" * role-name="Child-has-one-parent" * target-ejb="ExampleBean" * target-role-name="Parent-has-one-Child" * target-multiple="false" * * @jboss.relation fk-column="parentID" * related-pk-field="ID" * * @return */ public abstract ExampleLocal getParent(); /** * @ejb.interface-method */ public abstract void setParent(ExampleLocal el);
This setup is virtually identical to the one-to-many configuration defined above. The primary difference is that the target-multiple tag is defined as false rather than true. This lets XDoclet and the application server know that this is a one-to-one relationship, not a one-to-many relationship.