NHibernate exception on query

Posted by Yoav on Stack Overflow See other posts from Stack Overflow or by Yoav
Published on 2010-12-31T04:18:59Z Indexed on 2010/12/31 4:54 UTC
Read the original article Hit count: 336

I'm getting a mapping exception doing the most basic query. This is my domain class:

public class Project
{
    public virtual string PK { get; set; }
    public virtual string Id { get; set; }
    public virtual string Name { get; set; }
    public virtual string Description { get; set; }
}

And the mapping class:

public class ProjectMap :ClassMap<Project>
{
    public ProjectMap()
    {
        Table("PROJECTS");
        Id(x => x.PK, "PK");
        Map(x => x.Id, "ID");
        Map(x => x.Name, "NAME");
        Map(x => x.Description, "DESCRIPTION");
    }
}

Configuration:

public ISessionFactory SessionFactory
{
    return Fluently.Configure()
        .Database(MsSqlCeConfiguration.Standard.ShowSql().ConnectionString(c => c.Is("data source=" + path)))
        .Mappings(m => m.FluentMappings.AddFromAssemblyOf<Project>())
        .BuildSessionFactory();

}

And query: IList project;

using (ISession session = SessionFactory.OpenSession())
{
    IQuery query = session.CreateQuery("from Project");
    project = query.List<Project>();
}

I'm getting the exception on the query line:

NHibernate.Hql.Ast.ANTLR.QuerySyntaxException: Project is not mapped [from Project]
   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.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)

I assume something is wrong with my query.

© Stack Overflow or respective owner

Related posts about nhibernate

Related posts about fluent-nhibernate