-->
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.  [ 3 posts ] 
Author Message
 Post subject: composite unique id
PostPosted: Thu Sep 08, 2005 10:35 am 
Beginner
Beginner

Joined: Thu Sep 08, 2005 10:29 am
Posts: 21
Hibernate version: 3.0


How can I define a composite unique key in my hibernate mapping.
I have for example the following table:

Product
- id <id>
- productgroup_id <fk>
- code
- description
- price

Now I want to define two composite unique keys:
1: productgroup_id + code
2: productgroup_id + description

In words: a product code should be unique within the productgroup.
The same counts for the description.

Regards,
Marcel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 08, 2005 10:56 am 
Newbie

Joined: Wed Sep 07, 2005 5:54 am
Posts: 16
Location: Chambéry
<hibernate-mapping>
<class table="product" name="xxxx.Product">
<id name="id" type="long" column="id">
<generator class="increment"/>
</id>

<properties name="fsUniqueValue" unique="true">
<property name="idDocument" column="idDocument" index="FeatStatDocExtSectFeat" not-null="false" type="long" insert="false" update="false"/>
<property name="idSection" column="idSection" index="FeatStatDocExtSectFeat" not-null="false" type="integer" insert="false" update="false"/>
<property name="idExtraction" column="idExtraction" index="FeatStatDocExtSectFeat" not-null="false" type="integer" insert="false" update="false"/>
<many-to-one class="com.temis.tm.model.Feature" index="FeatStatDocExtSectFeat" name="feature" not-null="true">
<column name="idFeature"/>
</many-to-one>
<property name="leaf" column="leaf" type="boolean"/>
</properties>
<property name="frequency" column="frequency" not-null="true" type="integer"/>
<property name="idFatherFeature" column="idFatherFeature" not-null="true" type="long"/>

<many-to-one class="com.temis.tm.model.Feature" name="feature" not-null="true" column="idFeature" insert="false" update="false"/>
</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 08, 2005 11:01 am 
Newbie

Joined: Wed Sep 07, 2005 5:54 am
Posts: 16
Location: Chambéry
xfarret wrote:
<hibernate-mapping>
<class table="product" name="xxxx.Product">
<id name="id" type="long" column="id">
<generator class="increment"/>
</id>

<properties name="fsUniqueValue" unique="true">
<property name="idDocument" column="idDocument" index="FeatStatDocExtSectFeat" not-null="false" type="long" insert="false" update="false"/>
<property name="idSection" column="idSection" index="FeatStatDocExtSectFeat" not-null="false" type="integer" insert="false" update="false"/>
<property name="idExtraction" column="idExtraction" index="FeatStatDocExtSectFeat" not-null="false" type="integer" insert="false" update="false"/>
<many-to-one class="com.temis.tm.model.Feature" index="FeatStatDocExtSectFeat" name="feature" not-null="true">
<column name="idFeature"/>
</many-to-one>
<property name="leaf" column="leaf" type="boolean"/>
</properties>
<property name="frequency" column="frequency" not-null="true" type="integer"/>
<property name="idFatherFeature" column="idFatherFeature" not-null="true" type="long"/>

<many-to-one class="com.temis.tm.model.Feature" name="feature" not-null="true" column="idFeature" insert="false" update="false"/>
</class>
</hibernate-mapping>


Sorry mismatch with my keyboard

<hibernate-mapping>
<class table="product" name="xxxx.Product">
<id name="id" type="long" column="id">
<generator class="increment"/>
</id>

<properties name="fsUniqueValue" unique="true">
<property name="productgroup_id" column="productgroup_id" not-null="xxx" type="xxx" insert="false" update="false"/>
<property name="code" column="code" type="xxx" insert="false" update="false"/>
</properties>

<properties name="fsUniqueValue2" unique="true">
<property name="productgroup_id" column="productgroup_id" not-null="xxx" type="xxx" insert="false" update="false"/>
<property name="description" column="description" not-null="xxx" type="xxx" insert="false" update="false"/>
</properties>

<property name="description" .../>
<property name="code" .../>

Sorry again for my first message

Xavier


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

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.