• 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 ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

Question about Entity Relationships CMR

Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Something is a bit unclear about what it means to "set" a virtual relationship field.
Headfirst gives an example of a relationship scenario with two beans/databases, one for movies and one for directors. The CMR has one director linked to many movies. The underlying database for movies has a Director field, where the value stored is essentially the key from the underlying database for directors.
Suppose that we were working with a movie, and we wanted to change the director associated with it. Assuming that we have a reference to the component interface of the director that we want, do we just call the setter method for our relationship, say something defined in code like:
public abstract void setDirector(Director d);
we call from our code with:
This seems a bit weird to me. So with this call the container automatically knows that it has to change the Director key listed in the movie database entry for our movie? How the heck does it know that?
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It may seem strange, but that's really the way it works.
Remember, the wonderful thing about EJB is that the container takes care of all the complicated things, leaving you to worry about the stuff that really matters!
So, when we do EJB stuff, we work with actual beans, not primary keys and all that crazy database stuff. In addition, since all we have are the component interfaces, we don't have any choices as far as throwing around primary keys. In fact, in some applications we may not even be able to see primary keys!
Just throw around directors and movies and you'll be okay. That really is the way it works now.
He's dead Jim. Grab his tricorder. I'll get his wallet and this tiny ad:
a bit of art, as a gift, the permaculture playing cards
    Bookmark Topic Watch Topic
  • New Topic