I am using hibernate 3.2.1, java 6
What would be the correct way of mapping the following scenario in hibernate?
I want to acheive the following:
User table
------------
A
B
C
Products table
----------------
P1
P2
P3
Products Rating table
--------------------------
R1 P1 A
R2 P1 A
R3 P1 A
R4 P3 A
R5 P1 C
R6 P1 C
R7 P2 C
Currently I am using 1-n between User and Rating (means each user can rate multiple times and a rating is by a specific user), and 1-n between Product and Rating(means each product will have multiple ratings but each rating is only for a single product).
Somehow this mapping is not appealing me. Not sure what is wrong though.
On going through the hibernate document I found this
6.2.5. One-to-many associations A one to many association links the tables of two classes via a foreign key, with no intervening collection table. This mapping loses certain semantics of normal Java collections: * An instance of the contained entity class may not belong to more than one instance of the collection * An instance of the contained entity class may not appear at more than one value of the collection index
So my mapping is actually violating the first point. Can anybody please suggest what would be the correct way of mapping this scenario, in case I am doing it in a wrong way?
Thanks
|