First off, NHibernate won't prevent you from attempting to insert duplicate
records :) It simply builds in the Unique Constraints in the database. So if
you don't check for duplicates in your model, before you attempt to save
back using NHibernate, you will get a Unique Key Constraint violation
message back from your database.
Second, the two Id's you're mapping, how are those generated? Are they
assigned through some sort of bi-directional association in your model?
Typically I've seen this problem happen when you have an entity (such as
your ProductUsage class) that has two parents (two many-to-one mappings, or
Fluent's Reference() mapping). But in those cases, the actual classes would
be mapped using Fluent, not just an Id.

Could you perhaps post your ProductUsage class data definition, and any
other classes you're trying to map?

On Fri, Apr 3, 2009 at 9:55 AM, markunsworth <[email protected]> wrote:

>
> I have set up a composite unique key on two columns of a mapping (see
> below) but for some reason nHibernate still tries to insert records
> which are duplicate rows.
>
> I've looked around but there is very little in the way of help online.
> Has anyone else got this working/not working?
>
>
>
> public ProductUsageMap() {
>        WithTable("ProductUsage");
>        Id(x => x.Id).GeneratedBy.Identity().ColumnName("Id");
>        Map(x => x.ProductId).UniqueKey("Unique_ProductId_UsageTypeID");
>        Map(x => x.UsageTypeId).UniqueKey("Unique_ProductId_UsageTypeID");
>        Map(x => x.UsageStatusId);
> }
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Fluent NHibernate" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/fluent-nhibernate?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to