-->
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: Unique-key constraint and component collection !
PostPosted: Mon Jan 19, 2009 1:55 pm 
Newbie

Joined: Mon Aug 11, 2008 5:45 am
Posts: 15
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

2.0:

I have an entity (Person) which contains a collection of a component type (Address). I have defined the following mapping.

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" >
<class name="ABC.Person, ABC" table="person">
<id name="Id" type="guid" column="person_id">
<generator class="guid" />
</id>

<version name="Version" column="version" />
<property name="Name" />

<bag name="Addresses" table="person_addresses" lazy="true">
<key column="person_id" foreign-key="FK_Address_Person" />
<composite-element class="ABC.Address, ABC">
<property name="value" not-null="true"/>
</composite-element>
</bag>
</class>
</hibernate-mapping>


I want to define a unique constraint on component type such that the combination of "person_id" and "value" column should be unique. Altough "Property" tag has a "unique-key" attribute available but "key" tag doesn't allow anything like that.
One way to enforce uniqueness would be to use a set but that wouldn't create the Unique constraint in database and I am using hbm2ddl to generate the schema.


Help is much appreciated.

Cheers
Syed.


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.