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(); } }
|