This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Hi .. say i have three tables Override (Parent), OverrideItems (Link Table), Items (Child). Item has only two columns "ItemID" (primary key) and "ItemValue". When i add new Override and its items i would like to reuse existing ItemValue if user has entered existing ItemValue for the new Override. Otherwise inserts new ItemValue if none existing. I noticed a "many-to-many" unidirectional mapping will allow duplications meaning i could have same item inserted with different ItemID, how do i avoid this? Is making ItemValue UNIQUE Index/Constraint enough to enforce this
In your case, I guess you don't have item id's while saving Override instance because of which Hibernate would always try to insert new record for item instances. If you could manage to get items id's before saving then Hibernate would not insert new item record if it already exists.
In general, when you use many-to-many mapping, you have the IDs with you and that's how you implement many-to-many properly.