-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Unable to locate persister
PostPosted: Tue Dec 14, 2010 11:35 am 
Newbie

Joined: Tue Dec 14, 2010 11:19 am
Posts: 2
Hi

I am new to NHibernate and have just download NHibernate 3.0.0. I have followed some tutorials and checked out the Summer of NHibernate videos so feel that I have a grasp of the concepts and implementation but I am currently stumbling on a problem where NHibernate is throwing an exception stating that it is unable to locate a persister for one of my types.

I have a solution structure as follows:

DataTransferObjects (Class library project). This contains a simple object called History (code below)

Code:
namespace Venus.DataTransferObjects.History
{
    public class History
    {
        /// <summary>Gets/Sets the unique identifier of this history item</summary>
        /// <returns>Integer</returns>
        public virtual Int32 HistoryId { get; set; }

        /// <summary>Gets/Sets the unique identifier of the history type that this history item relates to</summary>
        /// <returns>Integer</returns>
        public virtual Int32 HistoryTypeId { get; set; }

        /// <summary>Gets/Sets the unique identifier of the item that has changed</summary>
        /// <returns>Integer</returns>
        /// <remarks>The item is determined by the HistoryTypeId, therefore an Issue would be identifier by this identifier it the history type related to an issue</remarks>
        public virtual Int32 Identifier { get; set; }

        /// <summary>Gets/Sets the old value of this history item</summary>
        /// <returns>String</returns>
        public virtual String OldValue { get; set; }

        /// <summary>Gets/Sets the new value of this history item</summary>
        /// <returns>String</returns>
        public virtual String NewValue { get; set; }

        /// <summary>Gets/Sets the date this history item was created</summary>
        /// <returns>Nullable(Of Date)</returns>
        public virtual DateTime CreatedDate { get; set; }

        /// <summary>Returns the NewValue of this history</summary>
        /// <returns>String</returns>
        public override string ToString()
        {
            return this.NewValue;
        }
    }
}

and I have a mapping file in the same location called History.hbm.xml containing the following:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="DataTransferObjects" namespace="Venus.DataTransferObjects.History">
  <class name="History" table="History">
    <id name="HistoryId" column="HistoryID" type="Int32" unsaved-value="0">
      <generator class="identity"></generator>
    </id>
    <property name="HistoryTypeId" column="HistoryTypeID" type="Int32" not-null="true" />
    <property name="Identifier" column="Identifier" type="Int32" not-null="true" />
    <property name="OldValue" column="OldValue" type="String" not-null="false" />
    <property name="NewValue" column="NewValue" type="String" not-null="false" />
    <property name="CreatedDate" column="CreatedDate" type="DateTime" not-null="false" />
  </class>
</hibernate-mapping>

The Assembly name for this project is set to "DataTransferObjects" and the Default namespace is set to "Venus".

Next I have a DataAccessLayer project (Class Library) which contains one provider class as follows:
Code:
namespace Venus.DataAccessLayer.History
{
    public class HistoryDataProvider
    {
        public DataTransferObjects.History.History GetHistoryById(Int32 historyId)
        {
            // Create a configuration object and have it configure itself, then buld a session factory based on this configuration
            NHibernate.ISessionFactory sessionFactory = (new NHibernate.Cfg.Configuration()).Configure().BuildSessionFactory();

            NHibernate.ISession session = sessionFactory.OpenSession();
            return session.Get<Venus.DataTransferObjects.History.History>(historyId);
        }
    }
}

The Assembly name for this project is "DataAccessLayer" and the Default namespace is "Venus".

I have also made the following references for this project:
    Antlr3.Runtime
    Castle.Core
    Castle.DynamicProxy2
    DataTransferObjects
    Iesi.Collections
    LinFu.DynamicProxy
    log4net
    NHibernate
    NHibernate.ByteCode.Castle
    NHibernate.ByteCode.LinFu
    Remotion.Data.Linq
The next project is called ServiceLayer (Class library) and contains one class:
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Venus.ServiceLayer.History
{
    public class History
    {
        public DataTransferObjects.History.History GetHistoryById(Int32 historyId)
        {
            Venus.DataAccessLayer.History.HistoryDataProvider provider = new Venus.DataAccessLayer.History.HistoryDataProvider();
            return provider.GetHistoryById(historyId);             
        }
    }
}

This is just simple at the moment but will be used for validation etc. at a later time.

Finally I have a DataAccessLayerTests project (Class library) which I am using as the runner for this application at the moment. This contains one test class called HistoryTests as follows:
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;

namespace Venus.DataAccessLayerTests.History
{
    [TestFixture]
    public class HistoryTests
    {
        [Test]
        public void CanGetHistoryItemById()
        {
            Venus.ServiceLayer.History.History service = new Venus.ServiceLayer.History.History();
            Venus.DataTransferObjects.History.History history = service.GetHistoryById(1);
           
        }

    }
}

There are currently no asserts as yet.

I have made the following references to this project:
    log4net
    NHibernate
    NHibernate.ByteCode.Castle
    NHibernate.ByteCode.LinFu
    nunit.Framework
    Remotion.Data.Linq
    ServiceLayer
This project also contains the hibernate.cfg.xml file as follows:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
  <session-factory name="VenusSQL2008">
    <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
    <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
    <property name="connection.connection_string">Data Source=(local);Initial Catalog=Venus;Integrated Security=true</property>
    <property name="dialect">NHibernate.Dialect.MsSql2008Dialect</property>
    <property name="show_sql">true</property>
    <property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
  </session-factory>
</hibernate-configuration>

When I run this test in the debugger I receive the exception "Unable to locate persister: Venus.DataTransferObjects.History.History". I am unsure if this is a problem with my namespaces or a configuration issue but I am having difficulty finding much information on the web regarding this.

Any help would be much appreciated.


Top
 Profile  
 
 Post subject: [Resolved] Unable to locate persister
PostPosted: Wed Dec 15, 2010 9:22 am 
Newbie

Joined: Tue Dec 14, 2010 11:19 am
Posts: 2
I figured out the problem. I was missing an mapping assembly in the hibernate.cfg.xml file for my DataTransferObjects assembly.

My configuration now looks like:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
  <session-factory name="VenusSQL2008">
    <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
    <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
    <property name="connection.connection_string">Data Source=(local);Initial Catalog=Venus;Integrated Security=true</property>
    <property name="dialect">NHibernate.Dialect.MsSql2008Dialect</property>
    <property name="show_sql">true</property>
    <property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>

    <mapping assembly="DataTransferObjects"/> <!-- This was missing -->
  </session-factory>
</hibernate-configuration>


This now works for my test and data is being retrieved correctly.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.