These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Subscriber is not mapped [from Subscriber s]
PostPosted: Thu Nov 05, 2009 11:43 am 
Newbie

Joined: Thu Nov 05, 2009 11:36 am
Posts: 6
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.cs
Code:
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 Layer
Code:
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


Top
 Profile  
 
 Post subject: Re: Subscriber is not mapped [from Subscriber s]
PostPosted: Thu Nov 05, 2009 11:53 am 
Newbie

Joined: Tue Jan 06, 2009 5:08 am
Posts: 10
Hello,

did you include the mapping file in your hibernate.cfg.xml?

Code:
<mapping resource="PATH_TO_XML/Subscriber.hbm.xml" />


Hope that helps.

Torti


Top
 Profile  
 
 Post subject: Re: Subscriber is not mapped [from Subscriber s]
PostPosted: Thu Nov 05, 2009 12:23 pm 
Newbie

Joined: Thu Nov 05, 2009 11:36 am
Posts: 6
No I didn't I'll try it out, does it make a difference if it's embedded?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.