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: Can I define both primary key and an alternate composite key
PostPosted: Thu May 13, 2010 5:00 pm 
Newbie

Joined: Thu May 13, 2010 4:38 pm
Posts: 1
Hi,

I've got a Store table with a primary key column (store_id) and a composite alternate key that comprises columns store_name and site_id.

I've got another table that references the Store table via store_id, and a third table that references the Store table via the composite store_name/site_id key.

So I really need to define Store's mapping to include both the primary key and the alternate composite key.

But when I define the mapping for Store table, I can define it with either the primary key of store_id or the composite key of store_name/site_id. When I include both, I get a MappingException saying that there is an "invalid child element 'composite-id' ".

It appears that I can't have both keys. Is this a known limitation of NHibernate?

BTW, I'm using NHibernate.Mapping.Attributes. The mapping file is below.

Thanks,

Phil

[Class(Table = "STORE", NameType = typeof(Store))]
public class Store
{
[Id(Name = "StoreId", Column = "store_id")]
public virtual int StoreId { get; set; }

[CompositeId(0)]
[KeyProperty(1, Name = "Name", Column = "store_name")]
[KeyProperty(2, Name = "SiteId", Column = "site_id")]

public virtual string Name { get; set; }

public virtual string SiteId { get; set; }

[ManyToOne(ClassType = typeof(Site), Column = "site_id", Fetch = FetchMode.Join)]
public virtual Site Site { get; set; }

public override bool Equals(object obj)
{
var other = obj as Store;
if (other == null)
return false;
return (SiteId == other.SiteId) &&
(Name == other.Name);
}

public override int GetHashCode()
{
return SiteId.GetHashCode() ^
Name.GetHashCode();
}
}


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.