views:

42

answers:

1

In my map I have:

Component(
    x => x.ExposureKey,
    m => {
        m.Map(x => x.AsOfDate).Not.Nullable();
        m.Map(x => x.ExposureId).Length(30).Not.Nullable();
    }
).Unique();

The relevant output from the HBM is

<component name="ExposureKey" insert="true" update="true" optimistic-lock="true" class="Some.Namespace.CreditExposureKey, Some.Namespace, Version=0.0.0.0, Culture=neutral, PublicKeyToken=aaaaaaaaaaaaaaaa">
    <property name="AsOfDate" type="System.DateTime, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
        <column name="AsOfDate" not-null="true"/>
    </property>
    <property name="ExposureId" type="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
        <column name="ExposureId" length="30" not-null="true"/>
    </property>
</component>

which is clearly missing unique="true" from the component definition.

Why is this happening?

A: 

Are you using the latest version of Fluent NHibernate? According to James Gregory (Fluent NHibernate contributor), it should work.

// Else, try this hack:
Component(x => x.ExposureKey, m => 
{
    m.Map(x => x.AsOfDate).Not.Nullable();
    m.Map(x => x.ExposureId).Length(30).Not.Nullable();
}).SetAttribute("unique", "true");

It would also be good to check if the generated SQL actually has the Unique property set even if the hbm mapping files do not (could be a small bug).

Rafael Belliard
I'll try a newer version (I'm using build 685 while current is 694). i think that `SetAttribute` has been removed. The generated SQL does not have the `unique` property set (and it shouldn't since it's not in the mapping!).
Jason
Updated to latest build (694). Still no go.
Jason
@Jason: This is odd++ and my VS at home is acting nuts. Hopefully you'll get an answer before I try replicating this at work (in about 12 hours). What is this, MSSQL/MySQL?
Rafael Belliard
Both MS SQL and SQLite. I don't think that matters though as this is a problem from Fluent NHibernate to the NHibernate mapping, not from NHibernate mapping to the database commands via SchemaExport.
Jason
@Jason: just wanted to know so I could test tomorrow on the nearest environment possible. :P
Rafael Belliard
@Rafael Belliard: Makes sense. Thanks for any help you can provide.
Jason