In p.400 of HFEJB, it said "we are not mapping the DirectorID column because we don't have a persistent CMP field for the DirectorID....That's where our CMR field comes in, but we don't map that to a database. Relationships happen by matching up two BEANS in the <relationships> part of the DD." This doesn't make sense to me. Suppose, in CMP, we don't have a persistent DirectorID field, when invoking ejbCreate(...) to insert a new Movie row to database, this new Movie row can' refer back to Director Table to find out its Director. And then the relationship between Movie and Director becomes useless when more and more new Move rows are inserted into Database. Is that an obvious problem? So I think we should make the DirectorID a persistent field, shouldn't we? If the above explanation is not correct, does Container automatically find Primary Key and Foreign Key Constraints and does Container will automatically add Foreign Key, DirectorID, to Movie Table according the Primary Key of Director Table? I'll appreciate for any response.
there is CMR field that maintains link to director and that is set in ejbPostCreate(). caller has to send the directorId value to ejbCreate() but it is not used there. CMR fields are set in ejbPostCreate() and thats where the code would be something like // get initial context // get director home directorRemote = directorHome.findByPrimaryKey(directoryId) now, user can call method on the EJB to get info about director through business methods defined in movie remote interface
Dear C Chavan Thank you for the reply. But I think I didn't make my question clear. My Question is when we want to insert an "NEW" Movie row to Movie Table and we don't have a persistent DirectorID field in ejbCreate() to insert this "NEW" Movie row to database, this "NEW" Movie row can't refer back to Director Table to find out its Director. I can understand directorRemote = directorHome.findByPrimaryKey(directoryId) But I can't understand we don't need persistent DirectorID field for "NEW" Movie row. Could you tell me more about it?
I'm intersted in this discussion. Hope I understand it. I am currently needing to put together a one-to-one relationship and need to understand the process if both beans need to have references to each other as they are created. I am imagining it would go something like this (create method of one ejb takes enough params to create both, the create method of the second takes a reference to the first and you uses a combination of create and post create to set up the persistent relationship): bean 1 (name):
Will this work? Is this the way to do it? Is there a better way? Any thoughts? Regards, Matthew
Matthew<br /> <br />Surrey, England<br /> <br />SCJP, SCBCD<br />Preparing: SCWCD, SCEA<br />My env: JBoss-4.0.0RC2 running on j2sdk1.4.2_06 running on Linux 2.6.11-1.14_FC3 running on Intel Pentium 4E Prescott 3.0GHz FSB800 1MB Cache on a ASUS P4S800 SiS648FX Socket 478 800FSB 3DDR 400 ATA133 motherboard