I guess this is what u want in sql. parent id need not be 0 just null if there is no parent.
(I dont have any ejbserver installed as of now. I am just studying for the certification and hopefully wont need to actually workout with it till I am done. I have only so much of time available. Anyway when I was studying for Java cert there was this guy who claimed he scored 100% (I scored a lousy 88% with all my notes making and hardwork) just by reading and understanding without writing even one line of code when he was studying. To make matters worse he was not even a Java programmer. So I want to see if thats really true with EJB certs also.
If someone has a ejbserver available and a databse maybe they would like to share their inputs.)
DROP TABLE TABLEA CASCADE CONSTRAINTS ;
CREATE TABLE TABLEA ( PK NUMBER NOT NULL, TEXT VARCHAR2 (4), PARENTID NUMBER, CONSTRAINT TABLEA_PK PRIMARY KEY ( PK ) );
Hi, Did u want How to create in the database or whether it can be implemented using entity beans. I guess it must be possible to implement it as CMR fields are nothing but virtual fields and you can reference an entity bean of the same type like am EMP-MGR classic Oracle Example.
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>
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.