NHibernate: No persister error

Posted by Mike on Stack Overflow See other posts from Stack Overflow or by Mike
Published on 2010-03-28T03:05:17Z Indexed on 2010/03/28 3:13 UTC
Read the original article Hit count: 621

Filed under:
|

Hello,

In my quest to further my knowledge, I'm trying to get get NHibernate running.

I have the following structure to my solution

  • Core Class Library Project
  • Infrastructure Class Library Project
  • MVC Application Project
  • Test Project

In my Core project I have created the following entity:

using System;

namespace Core.Domain.Model
{
    public class Category
    {
        public virtual Guid Id { get; set; }

        public virtual string Name { get; set; }
    }
}

In my Infrastructure Project I have the following mapping:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
         namespace="Core.Domain.Model"
         assembly="Core">

  <class name="Category" table="Categories" dynamic-update="true">
    <cache usage="read-write"/>
    <id name="Id" column="Id" type="Guid">
      <generator class="guid"/>
    </id>
    <property name="Name" length="100"/>
  </class>
</hibernate-mapping>

With the following config file:

<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
  <session-factory>
    <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
    <property name="connection.connection_string">server=xxxx;database=xxxx;Integrated Security=true;</property>
    <property name="show_sql">true</property>
    <property name="dialect">NHibernate.Dialect.MsSql2008Dialect</property>
    <property name="cache.use_query_cache">false</property>
    <property name="adonet.batch_size">100</property>
    <property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
    <mapping assembly="Infrastructure" />
  </session-factory>
</hibernate-configuration>

In my test project, I have the following Test

 [TestMethod]
        [DeploymentItem("hibernate.cfg.xml")]
        public void CanCreateCategory()
        {
            IRepository<Category> repo = new CategoryRepository();
            Category category = new Category();
            category.Name = "ASP.NET";

            repo.Save(category);

        }

I get the following error when I try to run the test:

Test method Volunteer.Tests.CategoryTests.CanCreateCategory threw exception: NHibernate.MappingException: No persister for: Core.Domain.Model.Category.

Any help would be greatly appreciated. I do have the cfg build action set to embedded resource.

Thanks!

© Stack Overflow or respective owner

Related posts about nhibernate

Related posts about asp.net-mvc