Nhibernate error: No persister for

Asked

Viewed 436 times

0

I would like some help regarding the error presented when I try to record records with Nhibernate by XML mapping.

The project has separate layers.

In the domain project, is my entity:

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();
        }
    }
}

Both xmls are with 'Embedded Resource' and 'Copy Always'.

I believe that 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 it does not map the xml class property to the entity specified therein.

Details of the error:

No persister for: Nhibernatetesteweb.domain.Entity.Company

The last call described on the tracking stack:

At Nhibernate.Impl.Sessionfactoryimpl.Getentitypersister(String entityName)

  • What Assembly.GetExecutingAssembly() returns? Add this line Assembly currentAssem = Assembly.GetExecutingAssembly(); before the _sessionFactory = new Configuration().Configure().BuildSessionFactory(); and Inspecione to return. It has to be NHibernateTesteWeb

  • Data, Version=1.0.0.0, Culture=neutral, Publickeytoken=null

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.