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

In 2 way CMR doubts regarding multiplicity and directionality?

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).
 
Phanindra Nayani
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I appreciate your help Anthony !
 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic