-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Uniqueness in association table of many-to-many association
PostPosted: Tue Sep 12, 2006 6:02 am 
Newbie

Joined: Tue Sep 12, 2006 5:16 am
Posts: 5
Location: Ukraine
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.