Assume a Table like Employee with the following fields:
EmpId,EmpName,EmpAddress & manager which is the referential integrity field with EmpId of the same table
The UML can be shown (or not) something like this ( considering a bi directional relationship,but in this case we can also say it is unidirectional if we dont want to implement the functionality to get to employees of a manager )
couldnt draw the UML - gave up.
Hope it is clear
The ejb-jar can be as follows:
<ejb-jar>
<display-name>EmployeeJar</display-name>
<enterprise-beans>
<entity>
<display-name>EmployeeBean<.display-name>
<ejb-name>EmployeeBean</ejb-name>
<local-home>EmployeeLocalHome</local-home>
<local>EmployeeLocal</local>
<!-- in this case u need bot the local and remote interface declared as CMR field can return only its local component interface-->
<home>EmployyeHome<home>
<remote>Employee</remote>
<ejb-class>EmployeeBean</ejb-class>
<persistent-type>Contaner</persistent-type>
<prim-key-class>jva.lang.String</prim-key-class>
<reentrant>false</reentrant>
<cmp-version>2.x</cmp-version>
<abstract-schema-name>EmployeeSchema</abstract-schema-name>
<cmp-field>
<field-name>empId</field-name>
</cmp-field>
<cmp-field>
<field-name>empName</field-name>
</cmp-field>
<cmp-field>
<field-name>empAddress</field-name>
</cmp-field>
<!--do not define mgrId as it is a relationship field-->
<primkey-field>empId</primkey-field>
<!--
.
. define oher req. fields if any
.
-->
</entity>
</enterprise-beans>
<!-- notice only one bean defination-->
<relationships>
<ejb-relation>
<ejb-relationship-role>
<ejb-relationship-role-name>Manager</ejb-relationship-role-name><!-- cancall it anything-->
<multiplicity>One</multiplicity>
<relationship-role-source>
<ejb-name>EmployeeBean</ejb-name>
</relationship-role-source>
<cmr-field>
<cmr-field-name>employees</cmr-field-name>
<cmr-field-type>Collection</cmr-field-type>
</cmr-field>
</ejb-relationship-role>
<ejb-relationship-role>
<ejb-relationship-role-name>Employee</ejb-relationship-role-name><!-- cancall it anything-->
<multiplicity>Many</multiplicity>
<relationship-role-source>
<ejb-name>EmployeeBean</ejb-name>
</relationship-role-source>
<cmr-field>
<cmr-field-name>manager</cmr-field-name>
<!-- no field type required, its the local component interfaceof the employeeBean-->
</cmr-field>
</ejb-relationship-role>
</ejb-relation>
</relationships>
</ejb-jar>
assign the virtual field manager its value by finding the Employee bean having the emp id of the manager specified in the create arguments within the ejbPostCreate(...) method.
You can also refer to HFEJB chapter on entity bean relationships and replace movied and director to one Employee table andbuild up from there.
Hope this works, I havent tried it but somebody let me know if and where i am wrong.
Regards,
[ October 12, 2004: Message edited by: Nileesha Bojjawar ]