NHibernate stored procedure problem

Posted by Calvin on Stack Overflow See other posts from Stack Overflow or by Calvin
Published on 2010-04-07T03:39:48Z Indexed on 2010/04/07 3:43 UTC
Read the original article Hit count: 330

Filed under:
|

I'm having a hard time trying to get my stored procedure works with NHibernate. The data returned from the SP does not correspond to any database table.

This is my mapping file:

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

    <sql-query name="DoSomething">
        <return class="SomeClass">
            <return-property name="ID" column="ID"/>
        </return>
        exec [dbo].[sp_doSomething]
    </sql-query>

</hibernate-mapping>

Here is my domain class:

namespace DomainModel.Entities
{
    public class SomeClass
    {
        public SomeClass()
        {
        }
        public virtual Guid ID
        {
            get;
            set;
        }
    }
}

When I run the code, it fails with

Exception Details: NHibernate.HibernateException: Errors in named queries: {DoSomething}

at line 80

Line 78:             config.Configure(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "NHibernate.config"));            
Line 79: 
Line 80:             g_sessionFactory = config.BuildSessionFactory();       

When I debug into NHibernate code, it seems that SomeClass is not added to the persister dictionary because there isn't a class mapping (only sql-query) defined in hbm.xml. And later on in CheckNamedQueries function, it is not able to find the persistor for SomeClass.

I've checked all the obvious things (e.g. make hbm as an embedded resource) and my code isn't too much different from other samples I found on the web, but somehow I just can't get it working. Any idea how I can resolve this issue?

© Stack Overflow or respective owner

Related posts about nhibernate

Related posts about hbm