• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question about Entity Relationships CMR

 
Christopher Arthur
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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:
setDirector(NewDirector);
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?
 
Nathaniel Stoddard
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic