Not sure about this, named queries are hard to debug, but have you tried prefixing the stored procedure name with its schema, like in "dbo.spGetMeasureValues"?
I'm new to nhibernate and fluent nhibernate. For one of our projects we are using fluent hibernate which works fine, we would like to extend this to support .hbm.xml files mainly to execute stored procedures on legacy systems. I've find many articles which helped me for getting started like
But there is an exception encountered while building session factory. InnerException: Errors in named queries: {GetMeasures} StackTrae: at NHibernate.Impl.SessionFactoryImpl..ctor(Configuration cfg, IMapping mapping, Settings settings, EventListeners listeners) at NHibernate.Cfg.Configuration.BuildSessionFactory() at FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory()
Here is my configuration Adding Asemblies:
configuration.Mappings(m => m.FluentMappings.AddFromAssembly(mapAssm));
configuration.Mappings(m => m.HbmMappings.AddFromAssembly(mapAssm));
Here is my *.hbm.xml
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" auto-import="true" assembly="MockTest" namespace="MockTest.Models">
<sql-query name="GetMeasures" callable ="true">
<query-param name="Location" type="string" />
<query-param name="StartDate" type="string" />
<query-param name="EndDate" type="string" />
<query-param name="RiskList" type="string" />
<return class="MockTest.Models.Measures">
<return-property column="MemberID" name="MemberID" />
<return-property column="Appointmentid" name="Appointmentid" />
<return-property column="LastName" name="LastName" />
<return-property column="FirstName" name="FirstName" />
<return-property column="MiddleName" name="MiddleName" />
<return-property column="MeasureData" name="MeasureData" />
</return>
exec spGetMeasureValues @Location = :Location,
@StartDate = :StartDate,
@EndDate = :EndDate,
@RiskList = :RiskList
</sql-query>
</hibernate-mapping>
Please let me know is there something wrong with this file? I tried wrapping stored procedure call as following
<!CDATA[[exec spGetMeasureValues @Location = :Location, ... ]]> but it didn't work
namespace MockTest.Models
{ public class Measures
{
public virtual string MemberID { get; set; }
public virtual int Appointmentid { get; set; }
public virtual string LastName { get; set; }
public virtual string FirstName { get; set; }
public virtual string MiddleName { get; set; }
public virtual string MeasureData { get; set; }
}
}
var query = session.GetNamedQuery("GetMeasures")
.SetString("Location", "88")
.SetDateTime("StartDate", startDate)
.SetDateTime("EndDate", endDate)
.SetString("RiskList", "1")
.List<Models.Measures>();
Measures ms = query[0];
Please look into this and provide some inputs.
Thanks
Shravan