• Post Reply Bookmark Topic Watch Topic
  • New Topic

CMR Design question  RSS feed

 
Ron Hamilton
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm new to container managed relationships and have hit a roadblock with my design of my "test" application. In a nutshell, I'm writing a simple application that allows Users to rate Movies. Many Users can rate many Movies, and many Movies can be rated by many Users. I have an entity bean for Users (id, name, email) and one for Movies (id, name, desc).
My thinking is that I don't need to create another entity bean for the Rating. I want to create a session bean that has an addRating() method. Is the relationship between the User and Movie entity beans enough? I simply want to connect those two beans by their id's and include a "rating" value as well.
Hope this makes some sense.
Thanks for any help in advance.
 
Nathaniel Stoddard
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, in UML terms, we would say that Rating can be designed as an association class. However, in EJB we don't really have association classes. You can model them with an interposing class, which imitates the actual association.
Movies<->MovieRating<->User
The eventual question you would come across if you only had Movie and User as classes in your application is: if more than one movie can be rated, I obviously can't store the rating in the movie, if a user can rate more than one movie, I can't store it in the user. Ya gotta store it somewhere else. (Thus the association class).
In the end, if properly designed, you would be able to do something like this:

And there you have it. (I have no idea if this will compile.) This should be pretty close to what you are thinking in your head.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!