-->
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.  [ 4 posts ] 
Author Message
 Post subject: Multi-column unique constraint on collection of components?
PostPosted: Mon Dec 29, 2008 2:59 pm 
Newbie

Joined: Mon Dec 29, 2008 2:20 pm
Posts: 5
I am trying to add a unique multi-column constraint on a collection of components. Usually, I would achieve this by using unique-key="xyz" on the properties in question. However, in this (probably not so) special case, I need the constraint to include the collection key (i.e. I need the components to be "unique per parent entity").

In the example below, I want to create a unique index on the COMPANY_PI table containing (company_id, year, branchId). Unfortunately, there is no unique-key attribute on the <key /> tag. Is there any way to achieve this through the hibernate mapping, other than using a <database-object /> with custom DDL?

Any ideas or alternative approaches?

Thanks,

Michael

Code:
    <class name="Company" table="COMPANY">
        ....

        <set name="performanceIndicators" table="COMPANY_PI">
            <key column="company_id" /> <!-- would like to use unique-key="abc" here -->
            <composite-element class="PerformanceIndicators">

                <property name="year" not-null="false" /> <!-- would like to use unique-key="abc" here -->
                <property name="branchId" not-null="false" column="branch_id" /> <!-- would like to use unique-key="abc" here -->

                <property name="..." not-null="false" />
            </composite-element>
        </set>

    </class>


Hibernate version:
3.2.6


Top
 Profile  
 
 Post subject: Re: Multi-column unique constraint on collection of componen
PostPosted: Tue Dec 30, 2008 3:37 pm 
Newbie

Joined: Tue Dec 30, 2008 3:29 pm
Posts: 4
Location: Netherlands
Hi,

As far as I know you can use the <key> element like this:

Code:
<key>
  <column name="company_id" unique-key="whatever_you_want" />
</key>


Regards,
Szabolcs


Last edited by szandrasi on Tue Dec 30, 2008 3:41 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Multi-column unique constraint on collection of componen
PostPosted: Tue Dec 30, 2008 3:39 pm 
Newbie

Joined: Tue Dec 30, 2008 3:29 pm
Posts: 4
Location: Netherlands
Hi,

As far as I know you can use the <key> element like this:

Code:
<key>
  <column name="company_id" unique-key="whatever_you_want" />
</key>


Regards,
Szabolcs


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 30, 2008 8:44 pm 
Newbie

Joined: Mon Dec 29, 2008 2:20 pm
Posts: 5
Hi Szabolcs,

what can I say? That was _exactly_ the one piece of information I was missing. Thanks a lot!

Regards,

Michael


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.