简体   繁体   English

NHibernate.MappingException无法确定类型:实体

[英]NHibernate.MappingException Could not determine type for: Entity

i have a asp.net aplication and add a library with my domains objects and xml files. 我有一个asp.net应用程序,并添加了包含我的域对象和xml文件的库。

the trace is: 跟踪是:

Message=Could not determine type for: VaLibrary.Core.Domain.VAEmpresa, VaLibrary,    Version=1.0.5.18335, Culture=neutral, PublicKeyToken=null, for columns:    NHibernate.Mapping.Column(IdDev)

Source=NHibernate 来源= NHibernate的

i search in the web same error, but, solutions are for other mapping options (fluent, castle, etc.) not for xml 我在网络中搜索相同的错误,但是解决方案针对其他映射选项(流利,城堡等),而不针对xml

my Code class is here 我的代码课在这里

using System;
   using System.Text;
   using System.Collections.Generic;
   namespace VaLibrary.Core.Domain {

    public class VAEmpresa {
        private int? _id;
        private string _nombre;
        private string _tipo;
        public VAEmpresa() {
            VAJu_Dev = new List<VAJu>();
            VAJu_Pub = new List<VAJu>();
        }
        public virtual int Id {
            get {
                return (int)this._id;
            }
            set {
                this._id = value;
            }
        }
        public virtual string Nombre {
            get {
                return this._nombre;
            }
            set {
                this._nombre = value;
            }
        }
        public virtual string Tipo {
            get {
                return this._tipo;
            }
            set {
                this._tipo = value;
            }
        }
        public virtual IList<VAJu> VAJu_Dev { get; set; }
        public virtual IList<VAJu> VAJu_Pub { get; set; }
    }
}

and reference is: 参考是:

using System;
using System.Text;
using System.Collections.Generic;
namespace VaLibrary.Core.Domain {

    public class VAJu {
        private int? _id;
        private VAEmpresa _idDev;
        private VAEmpresa _idPub;
        private VACon _vACon;
        private string _titulo;
        private int _numerop;
        public VAJu() {
            VApllist = new List<VApllist>();
        }
        public virtual int Id {
            get {
                return (int)this._id;
            }
            set {
                this._id = value;
            }
        }
        public virtual VAEmpresa IdDev {
            get {
                return this._idDev;
            }
            set {
                this._idDev = value;
            }
        }
        public virtual VAEmpresa IdPub {
            get {
                return this._idPub;
            }
            set {
                this._idPub = value;
            }
        }
        public virtual VACon VACon {
            get {
                return this._vACon;
            }
            set {
                this._vACon = value;
            }
        }
        public virtual string Titulo {
            get {
                return this._titulo;
            }
            set {
                this._titulo = value;
            }
        }
        public virtual int Numerop {
            get {
                return this._numerop;
            }
            set {
                this._numerop = value;
            }
        }
        public virtual IList<VApllist> VApllist { get; set; }
    }
}

the mappings files are: 映射文件为:

<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping assembly="VaLibrary" namespace="VaLibrary.Core.Domain" xmlns="urn:nhibernate-mapping-2.2">
  <class name="VAEmpresa" table="VA-Empresa" lazy="true" >
    <id name="Id" column="Id">
      <generator class="identity" />
    </id>
    <property name="Nombre">
      <column name="nombre" sql-type="varchar" not-null="true" />
    </property>
    <property name="Tipo">
      <column name="tipo" sql-type="varchar" not-null="false" />
    </property>
    <bag name="VAJu_Dev" inverse="true" cascade="none">
      <key column="IdDev" />
      <one-to-many class="VaLibrary.Core.Domain.VAJu, VaLibrary" />
    </bag>
    <bag name="VAJu_Pub" inverse="true" cascade="none">
      <key column="IdPub" />
      <one-to-many class="VaLibrary.Core.Domain.VAJu, VaLibrary" />
    </bag>
  </class>
</hibernate-mapping>

and

<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping assembly="VaLibrary" namespace="VaLibrary.Core.Domain" xmlns="urn:nhibernate-mapping-2.2">
  <class name="VAJu" table="VA-Ju" lazy="true" >
    <id name="Id" column="Id">
      <generator class="identity" />
    </id>
    <property name="Titulo">
      <column name="Titulo" sql-type="varchar" not-null="true" />
    </property>
    <many-to-one insert="false" update="false" lazy="false" name="IdDev">
      <column name="IdDev" sql-type="int" not-null="true" />
    </many-to-one>
    <property name="IdDev">
      <column name="IdDev" sql-type="int" not-null="true" />
    </property>
    <many-to-one insert="false" update="false" lazy="false" name="IdPub">
      <column name="IdPub" sql-type="int" not-null="true" />
    </many-to-one>
    <property name="IdPub">
      <column name="IdPub" sql-type="int" not-null="true" />
    </property>  
    <property name="Numerop">
      <column name="numero-p" sql-type="int" not-null="true" />
    </property>
    <bag name="VApllist" inverse="true" cascade="none">
      <key column="IdJu" />
      <one-to-many class="VApllist" />
    </bag>
  </class>
</hibernate-mapping>

the relantionship in DB is: Va-Ju.IdDev FK to VA-Empresa.Id PK Va-JU.IdPub FK to VA-Empresa.Id PK DB中的重新分配是:Va-Ju.IdDev FK到VA-Empresa.Id PK Va-JU.IdPub FK到VA-Empresa.Id PK

i try to change for but is the same. 我尝试更改,但相同。

I can do? 我可以?

thank you very much for your answers 非常感谢您的回答

[Edit] [编辑]

i use Nhibernate 3.2 我使用Nhibernate 3.2

The mapping is missing the correct relational (object to object) mapping. 该映射缺少正确的关系 (对象到对象)映射。 The best way how to explain that, is the example: 举例说明的最佳方法是:

Change this: 更改此:

private VAEmpresa _idDev;

public virtual VAEmpresa IdDev 
{
  get { return this._idDev; }
  set { this._idDev = value; }
}

Into this: 变成这个:

private VAEmpresa _dev;

public virtual VAEmpresa Dev  // Reference Object
{
  get { return this._idDev; }
  set 
  { 
      this._idDev = value; 
      if(_idDev != null)      // assure that with reference change
      {                       // the referenceId is changed as well
          IdDev = _idDev.Id
      }
  }
}
public virtual int IdDev { get; set; } // Refernece Id

Now we have two representations of the Dev reference (which is of type VAEmpresa and has int id) . 现在,我们有了Dev参考的两种表示形式(类型为VAEmpresa并具有int id) And we can map it working way. 我们可以将其映射为工作方式。 So 所以

Change this: 更改此:

<many-to-one insert="false" update="false" lazy="false" name="IdDev">
  <column name="IdDev" sql-type="int" not-null="true" />
</many-to-one>
<property name="IdDev">
  <column name="IdDev" sql-type="int" not-null="true" />
</property>

Into that: 变成:

<many-to-one name="Dev" class="VAEmpresa" column="IdDev"
         insert="false" update="false" lazy="false" />
<property name="IdDev" not-null="true" />

From that moment, NHibernate will know where to search for Dev property in DB. 从那时起,NHibernate将知道在DB中搜索Dev属性的位置。 It will be column IdDev and class to instantiate is VAEmpresa 它将是列IdDev ,要实例化的类是VAEmpresa

If the code requires just the referenceId IdDev ... we also have it. 如果代码只需要referenceId IdDev ...,我们也有。

SMALL NOTE: my experience is to use different readonly setting. 小注:我的经验是使用其他只读设置。 The editable is reference, readonly is referencId. 可编辑的是引用,只读的是referencId。 That forces the code to work with existing VAEmpresa objects, while IdDev could be any integer. 这迫使代码与现有的VAEmpresa对象一起工作,而IdDev可以是任何整数。 Handling is complicated, but brings fruits later 处理很复杂,但以后会带来成果

The ID may require a type. ID可能需要一种类型。 You have: 你有:

<id name="Id" column="Id">
  <generator class="identity" />
</id>

Try specifying a type as follows: 尝试如下指定类型:

<id name="Id" >
  <column name="Id" sql-type="int" not-null="true" unique="true" />
  <generator class="identity" />
</id>

Another problem is you forgot to put the name of the columns / domains in the bag property. 另一个问题是您忘记将列/域的名称放在bag属性中。 You need to put the actual column name and not the property names. 您需要输入实际的列名,而不是属性名。 Let me show you for VAJu: 让我向您展示VAJu:

 <bag name="VApllist" inverse="true" cascade="none">
  <key column="Id"  />
  <one-to-many class="VaLibrary.Core.Domain.VApllist" column="Id"  />
 </bag>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 NHibernate.MappingException:没有持久性 - NHibernate.MappingException: No persister for NHibernate.MappingException:没有持久性:XYZ - NHibernate.MappingException: No persister for: XYZ NHibernate.MappingException:NHibernate.PropertyNotFoundException:在类中找不到属性的获取器 - NHibernate.MappingException: NHibernate.PropertyNotFoundException: Could not find a getter for property in class ASubClass没有持久性(NHibernate.MappingException)-流利地 - No persister (NHibernate.MappingException) for ASubClass - Fluently 我该如何解决NHibernate.MappingException - How do I resolve NHibernate.MappingException nhibernate无法确定实体异常的类型 - nhibernate Could not determine type for entity exception 流畅的NHibernate - HasManyToMany NHibernate.MappingException:映射中的重复列集合 - Fluent NHibernate - HasManyToMany NHibernate.MappingException: Repeated column in mapping for collection NHibernate无法确定X的类型 - NHibernate Could not determine type for X NHibernate.MappingException:没有持久性:NHibernateExperiment.Player-我找不到解决方案 - NHibernate.MappingException: No persister for: NHibernateExperiment.Player - i can't find the solution 通过代码进行Nhibernate映射,无法确定属性的类型 - Nhibernate mapping by code, Could not determine type for property
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM