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
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).
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.