Hi,
I'm new to NHibernate and started to make my own solution today.
I keep getting this error and I can't figure out how to fix it. I searched google and couldn't find a satisfactory answer.
Here's My code
Subscriber.hbm.xml (found in the same directory as the class)Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="IDI.DAL" namespace="IDI.DAL">
<class name="IDI.DAL.Subscriber,IDI.DAL" table="gntb_data_subscribers">
<id name="Id" type="Int32" column="Id">
<generator class="native" />
</id>
<property name="Name" column="Name" type="String" Length="400"/>
</class>
</hibernate-mapping>
Subscriber.csCode:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace IDI.DAL
{
public class Subscriber
{
public Subscriber(){}
public virtual int Id { get; set; }
public virtual string Name { get; set; }
}
}
The Data Access LayerCode:
public static ISession GetSession()
{
return new Configuration().Configure().BuildSessionFactory().GetCurrentSession();
}
public static IList<Subscriber> GetCustomerById(int id)
{
ISession session = GetSession();
return session.CreateQuery("from Subscriber s").List<Subscriber>();
}
And finally the test:
Code:
[Test]
public void CanGetCustomerById()
{
log4net.Config.XmlConfigurator.Configure();
IList<Subscriber> sub = DataAccessLayer.GetCustomerById(52);
Assert.AreEqual(0,sub.Count);
}
Here is the error message I am getting:
Code:
NHibernate.Hql.Ast.ANTLR.QuerySyntaxException: Subscriber is not mapped [from Subscriber s]
at NHibernate.Hql.Ast.ANTLR.SessionFactoryHelperExtensions.RequireClassPersister(String name)
at NHibernate.Hql.Ast.ANTLR.Tree.FromElementFactory.AddFromElement()
at NHibernate.Hql.Ast.ANTLR.Tree.FromClause.AddFromElement(String path, IASTNode alias)
at NHibernate.Hql.Ast.ANTLR.HqlSqlWalker.CreateFromElement(String path, IASTNode pathNode, IASTNode alias, IASTNode propertyFetch)
at NHibernate.Hql.Ast.ANTLR.HqlSqlWalker.fromElement()
at NHibernate.Hql.Ast.ANTLR.HqlSqlWalker.fromElementList()
at NHibernate.Hql.Ast.ANTLR.HqlSqlWalker.fromClause()
at NHibernate.Hql.Ast.ANTLR.HqlSqlWalker.unionedQuery()
at NHibernate.Hql.Ast.ANTLR.HqlSqlWalker.query()
at NHibernate.Hql.Ast.ANTLR.HqlSqlWalker.selectStatement()
at NHibernate.Hql.Ast.ANTLR.HqlSqlWalker.statement()
at NHibernate.Hql.Ast.ANTLR.HqlSqlTranslator.Translate()
at NHibernate.Hql.Ast.ANTLR.QueryTranslatorImpl.Analyze(HqlParseEngine parser, String collectionRole)
at NHibernate.Hql.Ast.ANTLR.QueryTranslatorImpl.DoCompile(IDictionary`2 replacements, Boolean shallow, String collectionRole)
at NHibernate.Hql.Ast.ANTLR.QueryTranslatorImpl.Compile(IDictionary`2 replacements, Boolean shallow)
at NHibernate.Engine.Query.HQLQueryPlan..ctor(String hql, String collectionRole, Boolean shallow, IDictionary`2 enabledFilters, ISessionFactoryImplementor factory)
at NHibernate.Engine.Query.QueryPlanCache.GetHQLQueryPlan(String queryString, Boolean shallow, IDictionary`2 enabledFilters)
at NHibernate.Impl.AbstractSessionImpl.GetHQLQueryPlan(String query, Boolean shallow)
at NHibernate.Impl.AbstractSessionImpl.CreateQuery(String queryString)
at IDI.DAL.DataAccessLayer.GetCustomerById(Int32 id) in DataAccessLayer.cs: line 21
at IDI.UnitTests.Tests.CanGetCustomerById() in Tests.cs: line 18
I am calling a database called gntb_data_subscribers which has the columns:
Id Int
Name VARCHAR(400)
If anyone can help me I've lost all faith in myself :-)
thanks.
E