NHibernate Mapping错误外键复合键

时间:2016-04-29 08:39:21

标签: nhibernate foreign-keys composite

我是NHibernate的新手。 我打开Nhibernate会话时出现此错误消息。

L'exception NHibernate.FKUnmatchingColumnsException n'a pas été gérée par le code utilisateur
  HResult=-2146232832
  Message=Foreign key (FK918CBDA3D2011229:COUNTRY [elt])) must have same number of columns as the referenced primary key (TRANSLATIONKEY [ORIGIN, CODE])
  Source=NHibernate
  StackTrace:
       à NHibernate.Cfg.Configuration.LogAndThrow(Exception exception)
       à NHibernate.Cfg.Configuration.SecondPassCompileForeignKeys(Table table, ISet`1 done)
       à NHibernate.Cfg.Configuration.SecondPassCompile()
       à NHibernate.Cfg.Configuration.BuildSessionFactory()
       à Poc_Webapi_Oracle_NHi.Controllers.NHibernateSession.OpenSession() dans C:\Users\CSO\Documents\Visual Studio 2015\Projects\Poc-Webapi-Oracle-Nhi\Poc-Webapi-Oracle-NHi\Controllers\NHibernateSession.cs:ligne 35
       à Poc_Webapi_Oracle_NHi.Controllers.Persistance.GlobalCardRepository.Get(Int32 id) dans C:\Users\CSO\Documents\Visual Studio 2015\Projects\Poc-Webapi-Oracle-Nhi\Poc-Webapi-Oracle-NHi\Controllers\Persistance\GlobalCardRepository.cs:ligne 42
       à Poc_Webapi_Oracle_NHi.Controllers.GlobalCardController.GetGlobalCardById(Int32 id) dans C:\Users\CSO\Documents\Visual Studio 2015\Projects\Poc-Webapi-Oracle-Nhi\Poc-Webapi-Oracle-NHi\Controllers\GlobalCardController.cs:ligne 24
       à lambda_method(Closure , Object , Object[] )
       à System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)
       à System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)
       à System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)
  InnerException: 

这是例外情况...... 我会用你的评论编辑代码,来找你,知道它是什么。

Translationkey.cs

[Serializable]
public partial class Translationkey
{
    public Translationkey()
    {
        Activities = new Iesi.Collections.Generic.LinkedHashSet<Activity>();
        Contactroles = new Iesi.Collections.Generic.LinkedHashSet<Contactrole>();
        Countries = new Iesi.Collections.Generic.LinkedHashSet<Country>();
        Languages = new Iesi.Collections.Generic.LinkedHashSet<Language>();
        Translations = new Iesi.Collections.Generic.LinkedHashSet<Translation>();
        Userroles = new Iesi.Collections.Generic.LinkedHashSet<Userrole>();     
    }
    public virtual string Code
    {
        get;
        set;
    }
    public virtual string Origin
    {
        get;
        set;
    }
    public virtual Iesi.Collections.Generic.LinkedHashSet<Activity> Activities
    {
        get;
        set;
    }
    public virtual Iesi.Collections.Generic.LinkedHashSet<Contactrole> Contactroles
    {
        get;
        set;
    }
    public virtual Iesi.Collections.Generic.LinkedHashSet<Country> Countries
    {
        get;
        set;
    }
    public virtual Iesi.Collections.Generic.LinkedHashSet<Language> Languages
    {
        get;
        set;
    }
    public virtual Iesi.Collections.Generic.LinkedHashSet<Translation> Translations
    {
        get;
        set;
    }
    public virtual Iesi.Collections.Generic.LinkedHashSet<Userrole> Userroles
    {
        get;
        set;
    }

    public override bool Equals(object obj)
    {
        if (ReferenceEquals(this, obj))
            return true;

        return Equals(obj as Translationkey);
    }

    public virtual bool Equals(Translationkey obj)
    {
        if (obj == null) return false;

        if (Equals(Code, obj.Code) == false) return false;
        if (Equals(Origin, obj.Origin) == false) return false;
        return true;
    }

    public override int GetHashCode()
    {
        int result = 1;

        result = (result * 397) ^ (Code != null ? Code.GetHashCode() : 0);
        result = (result * 397) ^ (Origin != null ? Origin.GetHashCode() : 0);
        return result;
    }
}

Country.cs

[Serializable]
public partial class Country
{
    public Country()
    {
        Countrycards = new Iesi.Collections.Generic.LinkedHashSet<Countrycard>();       
    }
    public virtual double Id
    {
        get;
        set;
    }
    public virtual Iesi.Collections.Generic.LinkedHashSet<Countrycard> Countrycards
    {
        get;
        set;
    }
    public virtual Language Language
    {
        get;
        set;
    }
    public virtual Translationkey Translationkey
    {
        get;
        set;
    }

    public override bool Equals(object obj)
    {
        if (ReferenceEquals(this, obj))
            return true;

        return Equals(obj as Country);
    }

    public virtual bool Equals(Country obj)
    {
        if (obj == null) return false;

        if (Equals(Id, obj.Id) == false) return false;
        return true;
    }

    public override int GetHashCode()
    {
        int result = 1;

        result = (result * 397) ^ Id.GetHashCode();
        return result;
    }
}

}

TranslationKey.hbm

<class name="Translationkey" table="`TRANSLATIONKEY`" schema="`ADMINIMMOCHAN`">
    <composite-id>
        <key-property name="Origin" column="`ORIGIN`" />
        <key-property name="Code" column="`CODE`" />
    </composite-id>
    <set name="Activities" inverse="true" cascade="all">
        <key>
            <column name="`ORIGINTSLKEY`" />
            <column name="`CODETSLKEY`" />
        </key>
        <one-to-many class="Activity" />
    </set>
    <set name="Contactroles" inverse="true" cascade="all">
        <key>
            <column name="`ORIGINTSLKEY`" />
            <column name="`CODETSLKEY`" />
        </key>
        <one-to-many class="Contactrole" />
    </set>
    <set name="Countries" table="`COUNTRY`" inverse="true" cascade="all">
        <key>
            <column name="`ORIGINTSLKEY`" />
            <column name="`CODETSLKEY`" />
        </key>
        <one-to-many class="Country" />
    </set>
    <set name="Languages" table="`COUNTRY`" cascade="all">
        <key>
            <column name="`ORIGINTSLKEY`" />
            <column name="`CODETSLKEY`" />
        </key>
        <many-to-many class="Language" column="`IDLNG`" />
    </set>
    <set name="Translations" inverse="true" cascade="all">
        <key>
            <column name="`ORIGINTSLKEY`" />
            <column name="`CODETSLKEY`" />
        </key>
        <one-to-many class="Translation" />
    </set>
    <set name="Userroles" inverse="true" cascade="all">
        <key>
            <column name="`ORIGINTSLKEY`" />
            <column name="`CODETSLKEY`" />
        </key>
        <one-to-many class="Userrole" />
    </set>
</class>

Country.hbm

<class name="Country" table="`COUNTRY`" schema="`ADMINIMMOCHAN`">
    <id name="Id" access="property" column="`ID`" length="22">
        <generator class="assigned" />
    </id>
    <set name="Countrycards" inverse="true" cascade="all">
        <key column="`IDCTY`" />
        <one-to-many class="Countrycard" />
    </set>
    <many-to-one name="Language" class="Language" column="`IDLNG`" not-null="true" cascade="all" fetch="select" />
    <many-to-one name="Translationkey" class="Translationkey" not-null="true" cascade="all" fetch="select">
        <column name="`ORIGINTSLKEY`" />
        <column name="`CODETSLKEY`" />
    </many-to-one>
</class>

我不明白为什么因为我有相同数量的列。 在被探索的科目中的每一个,没有这样的信息“[elt]” 有关信息,我使用的是Oracle数据库。

谢谢

0 个答案:

没有答案