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: many-to-many with a unique constraint for multiple columns
PostPosted: Fri Oct 16, 2009 3:40 pm 
Newbie

Joined: Tue Apr 29, 2008 1:42 pm
Posts: 12
Hi everybody.

I am having a problem while using many-to-many with a unique constraint (so that the collection acts as one-to-many).

I have three classes - Orderline, OrderLineId, and Order. The class Orderline has a composite id of type OrderLineId and is mapped in two tables i.e. ORDERLINE and LINKTABLE. The class Order has a unidirectional one-to-many association with the class Orderline.

Here is my mapping -
<hibernate-mapping>
<class name="Orderline" table="ORDERLINE">
<composite-id name="id" class="OrderLineId">
<key-property name="lineId" column="LINEID"/>
<key-property name="orderId" column="ORDERID"/>
<key-property name="customerId" column="CUSTOMERID"/>
</composite-id>
<property name="name" column="NAME"/>
<join table="LINKTABLE">
<key>
<column name="LINEID"/>
<column name="ORDER_ID"/>
<column name= "CUSTOMERID"/>
</key>
<property name="typename" column="TYPENAME"/>
</join>

</class>

<class name="Order" table="ORDERTABLE">
<id name="id" column="ORDER_ID" type="java.lang.Long">
<generator class="increment"/>
</id>
<property name="orderName" column="ORDER_NAME"/>
<set name="orderLines" table="LINKTABLE">
<key>
<column name="ORDER_ID"/>
</key>
<many-to-many class="Orderline" unique="true">
<column name= "LINED"/>
<column name= "ORDERID"/>
<column name= "CUSTOMERID"/>
</many-to-many>
</set>
</class>
</hibernate-mapping>

since I have a <join> tag, I am using many-to-many with a unique constraint. Am I supposed to add unique="true" in each column of a many-to-many tag?

Any help will be appreciated!!

Thank you.


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.