Named query not known error trying to call a stored proc using Fluent NHibernate
- by Hamman359
I'm working on setting up NHibernate for a project and I have a few queries that, due to their complexity, we will be leaving as stored procedures. I'd like to be able to use NHibernate to call the sprocs, but have run into an error I can't figure out. Since I'm using Fluent NHibernate I'm using mixed mode mapping as recommended here. However, when I run the app I get a "Named query not known: AccountsGetSingle" exception and I can't figure out why. I think I might have a problem with my HBM mapping since I'm not very familiar with using them but I'm not sure.
My NHibernate configuration code is:
private ISessionFactory CreateSessionFactory()
{
return Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2005
.ConnectionString((conn => conn.FromConnectionStringWithKey("CIDB")))
.ShowSql())
.Mappings(m =>
{
m.HbmMappings.AddFromAssemblyOf<Account>();
m.FluentMappings.AddFromAssemblyOf<Account>();
})
.BuildSessionFactory();
}
My hbm.xml file is:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<sql-query name="AccountsGetSingle">
<return alias="Account" class="Core, Account"></return>
exec AccountsGetSingle
</sql-query>
</hibernate-mapping>
And the code where I am calling the sproc looks like this:
public Account Get()
{
return _conversation.Session
.GetNamedQuery("AccountsGetSingle")
.UniqueResult<Account>();
}
Any thoughts or ideas would be appreciated. Thanks.