Hello all. Consider two entities: User and PhotoPushpin. Each user can create pushpin, but also user can have favorite photo pushpins. We have many-to-many association between User and PhotoPushpin (in favoritePhotoPushpins collection). It is unidirectional.
The question is: how to prevent a user to add the same photo pushpin to favorite twice? It means: how to make the composite key of both fields in association table to prevent two records to be absolutely equal? Or another way: how to add a key field to association table? Or maybe there is another way to solve this?
I've found something if to use annotations:
Code:
@Table(name="tbl_sky", uniqueConstraints = {@UniqueConstraint(columnNames={"month", "day"})})
But I can't implement it because I use only XML. I believe that there is the way to do it by XML. But how?
Hibernate version: 3.1
Mapping documents:Association part of user.hbm.xml:
Code:
<bag name="favoritePhotoPushpins" table="favorite_pushpins" inverse="false" lazy="true">
<key column="USER_ID" />
<many-to-many class="com.shiftlabs.imagestroll.model.PhotoPushpin" column="PUSHPIN_ID" />
</bag>
Name and version of the database you are using: MySql 4.0.26-nt