wood burning stoves*
The moose likes EJB and other Java EE Technologies and the fly likes EJB and CMR questions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "EJB and CMR questions" Watch "EJB and CMR questions" New topic
Author

EJB and CMR questions

John Menarek
Greenhorn

Joined: Mar 24, 2004
Posts: 1
Hi,
I am new to EJB and have questions that pertain to two areas about CMR. The first area is conceptually how the EJBs and related entities are created. The second is about jbosscmp-jdbc.xml
Any help would be greatly appreciated
Reference for questions: BillingEJB has a ContactEJB, it�s a unidirectional one to one relationship
Note*** some of my assumptions maybe wrong to misconfiguration issues with JBoss
In regards to EJB creation and related entities

1.One can have a foreign key to another relation. But to what end? The BillingEJB can have the ContactEJB phone number pk. If I create a BillingEJB and use a �remote� ContactEJB I can only set the foreign key cmp. I cannot set the contact cmr field and the container does not use the foreign key to set it for me. At least when I tested creating an BillingEJB with a remote ContactEJB and trying to get the contacts name I got a null pointer exception because the cmr field was null. Is the foreign key only to aid in the use of �find� and �select� methods?
2.If my assertions are correct in the first question than it follows that the remote interface of an object with cmr relationships is essentially useless. I state this because the only way to set the CMR field is with a local interface in the postCreate method and you can only create a local interface in the container.
3.If my assertions are correct again than some higher level object, a session bean, a delegate, whatever will be required by the client to instantiate any entity beans with cmrs
In regards to jbosscmp-jdbc.xml and maybe this is why I am incurring some of my problems. My relationship from the BillingEJB to the ContactEJB looks like:
<ejb-relationship-role>
<ejb-relationship-role-name>
Billing-Has-Contact
</ejb-relationship-role-name>
<key-fields>
<key-field>
<!-- Note: Field in Billing. -->
<field-name>billingId</field-name>
<!-- Note: Column in Contact table. -->
<column-name>phoneNumber</column-name>
</key-field>
</key-fields>
</ejb-relationship-role>
As I understand it the reference EJB is Billing so why do I have specify its key? shouldn't it be something like

<key-fields>
<key-field>
<!-- Note: Field in Billing. -->
<field-name>contactPhoneNumber</field-name> THE FOREIGN KEY
<!-- Note: Column in Contact table. -->
<column-name>phoneNumber</column-name> THE PK in ContactEJB
</key-field>
</key-fields>
 
jQuery in Action, 2nd edition
 
subject: EJB and CMR questions