my dog learned polymorphism*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes In 2 way CMR doubts regarding multiplicity and directionality? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "In 2 way CMR doubts regarding multiplicity and directionality?" Watch "In 2 way CMR doubts regarding multiplicity and directionality?" New topic
Author

In 2 way CMR doubts regarding multiplicity and directionality?

Phanindra Nayani
Ranch Hand

Joined: Jan 18, 2004
Posts: 30
Hi,
Following doubts may sound silly, but still I am confused about them. Please help me to understand them.
If there are 2 entity types Movie and Director and they have 2 way CMR. As in HFEJB, every movie can have 1 director and director can drect 0..* movies. Let us assume entities movie1 and director1 of entity types Movie and Director. Here are my doudbts.
1) If movie1.setDirector(director1) is called, movie referes to director, in this case, will director1 automatically referes to movie1? i.e Will container set the relation in opposite direction or the client has to do it?
2) If director has to add/remove movie relations, getting the movie collection by director1.getMovies() and then adding/deleting movies to/from that collection object will automatically set/unset relations in the underlying entities(DB rows) automatically by the container?
3) If director1 is referring to movie7 and movie8 already, calling director.setMovies(null) will do what? Will it empty the movie collection object in director1 or will it make the reference to movie collection object in director1 as null?
4) If director1 is referring to movie7 and movie8 already, calling director.setMovies() with a collection object having movie3 and movie 4. After this will movie collection object in director1 have movie7, movie8, movie3 and movie 4? Or will movie collection object in director1 have movie3 and movie 4 only? i.e will it append or replace existing relations?
Thanks for your time,
Phani


IBM 486 (OOAD/UML)<br />SCJP 1.4<br />SCBCD<br />SCWCD<br />IBM WebSPhere Cert Admin (IBM-340)<br />Gonna prepare for WebLogic Cert
Anthony Watson
Ranch Hand

Joined: Sep 25, 2003
Posts: 327
1) The client does not have to do anything. Both the movie table and the director table will be updated appropriately when a call to movie1.setDirector(director1) is called. Both tables would still be updated with this method call even if you didn't put the cmr-field "movies" in the Director ejb-relationship-role. Only the bean that wants to call methods that refer to another bean need to delcare a cmr-field.
2) When you call director1.getMovies(), you get a collection of movie (castable) objects back. You can then additions or deletions from that collection but then you must call director1.setMovies(collection1) in order for the database changes to occur.
3) Empty the director's movie collection
4) The collection would only contain movie7 and movie8. The Director table would be updated (added refs to 7 and 8, deleted refs to 3 and 4). Then the Movie table would be updated (7 and 8 would refer to director1, 3 and 4 would not refer to director1).


Anthony W.<br />MCP, SCJP 1.4, SCJD, SCWCD 1.3, SCWCD 1.4, SCBCD
Phanindra Nayani
Ranch Hand

Joined: Jan 18, 2004
Posts: 30
I appreciate your help Anthony !
sonali rao
Ranch Hand

Joined: Nov 03, 2003
Posts: 64
I have a doubt about the answer given for the above mentioned 4th point. I interpreted in the following way. Let me know if I am wrong.
As the movie has a multiplicty of Many the reference of the movie will be copied and not moved.
So the director1 will have movie 3, movie 4, movie 7 & movie 8.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: In 2 way CMR doubts regarding multiplicity and directionality?