Why does Fluent NHibernate ignore my unique component constraint?

On my map there are:

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

The corresponding exit from 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 definition component.

Why is this happening?

+5
source share
1 answer

Are you using the latest version of Fluent NHibernate? According to James Gregory (NHibernate's free spokesperson), 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 useful to check whether the generated SQL really has a property Unique, even if the hbm mapping files cannot be (may be a small error).

0

All Articles