Defining relationships in your abstract persistence schema (in the DD)
CMP field definitions are so easy. You declare a <cmp-field> and give it a name that matches one of your getter/setter pairs (following the naming rule of dropping the “get” and “set” and beginning the CMP field name with a lower-case letter).
But CMR is more involved. You can’t be in a relationship with only yourself, so a relationship always includes two beans!
Define an ejb-relation between two beans
Note
Every relationship has exactly two beans.
Define an ejb-relationship-role for one bean
multiplicity for this bean
Note
Multiplicity of this bean (i.e. how many of this type will the OTHER participant have)
source for this bean
Note
Which bean are we really talking about?
cmr-field for this bean
Note
Must match the “virtual field” in the bean class
cascade-delete for this bean
Note
Only if THIS bean wants to be deleted when its partner is deleted.
Define an ejb-relationship-role for the second bean
multiplicity for this bean
source for this bean
cmr-field for this bean
cascade-delete for this bean
Note
Same stuff for the second participant in the relationship
Relationship definition for the Director-to-Movie relationship
Define an ejb-relation between two beans
<ejb-relation>
Note
Each <ejb-relation> describes one pair of beans... one relationship. They REALLY should have named this <ejb-relationship>
Define an ejb-relationship-role for ...
Get Head First EJB now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.