kungfujava wrote:
Well here are the reasons:
1. the key for PRODUCT_IMAGE isnt auto-generated. Instead the key is a Foreign key from PRODUCTS table's Primary Key. In every entry of the PRODUCT table, there is an entry in the PRODUCT_IMAGE.
As the error states, you'll need to override equals() to take this into account if you do this.
kungfujava wrote:
2. True I could create an ordinary mapping and have the PK defined by me, but that wont be a good design. I want to maintain relationship.
I still don't think composite id is correct for this case. The id is not a method for maintaining a relationship, but for assigning tuple identity. Use a constraint to seal the relationship.
Sounds like a standard one-to-one property instead:
http://www.hibernate.org/hib_docs/reference/en/html/mapping.html#mapping-declaration-onetoone