NHibernate error: No persister for

0

I would like help with the error when I try to write NHibernate records through XML mapping.

The project has separate layers.

In the domain project, my entity is:

namespace NHibernateTesteWeb.Domain.Entity
{
    public class Company
    {
        public virtual int Id { get; set; }
        public virtual string Name { get; set; }
    }
}

In the data access project is xml:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
    namespace="NHibernateTesteWeb.Domain.Entity" assembly="NHibernateTesteWeb">
  <class name="NHibernateTesteWeb.Domain.Entity.Company" table="Company">    
    <id name="Id">
      <column name="Id" sql-type="int" not-null="true"/>
      <generator class="native" />
    </id>    
    <property name="Name">
      <column name="Name" length="100" not-null="false" />      
    </property>    
  </class>
</hibernate-mapping>

and Nhibernate configuration file:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
  <session-factory>
    <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
    <property name="dialect">NHibernate.Dialect.MsSql2012Dialect</property>
    <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
    <property name="connection.connection_string">
      Server=(localdb)\Projects;initial catalog=TesteHibernate;Integrated Security=True
    </property>
    <property name="hbm2ddl.auto">create</property>
    <property name="show_sql">true</property>
    <mapping assembly="NHibernateTesteWeb"/>
  </session-factory>
</hibernate-configuration>

Still in the data access project is the NHibernateHelper class:

namespace NHibernateTesteWeb.Data.Helper
{
    public sealed class NHibernateHelper
    {
    ...    
        static NHibernateHelper()
        {
            _sessionFactory = new Configuration().Configure().BuildSessionFactory();
        }
    }
}

The two xmls have the 'Embedded Resource' and 'Copy always' option.

I believe the error may be related to the fact that NHibernate is in one project, and the entity in another. It apparently loads hibernate.cfg.xml and also Company.hbm.xml, but does not map the xml class property to the entity it lists.

Error Details:

  

No persister for: NHibernateTesteWeb.Domain.Entity.Company

The last call described in the trace stack:

  

at NHibernate.Impl.SessionFactoryImpl.GetEntityPersister (String entityName)

    
asked by anonymous 14.07.2018 / 23:33

0 answers