• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Question: HFEJB p.400 : Don't map DirectorID column

 
Ranch Hand
Posts: 166
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Steve Taiwan
Ranch Hand
Posts: 166
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic