简体   繁体   中英

NHibernate 2 HQL not working

I have a basic console application in which i using NHibernate V2.x to learn it. It is configured with FluentHibernate. I am facing a strange exception when executing the hql query to get all the users from user table. I know that user is reserved keyword,

so i tried SELECT * FROM [User] and it worked good with CreateSqlQuery method but then below failed miserably with the exception

Method 'HasAncestor' in type 'NHibernate.Hql.Ast.ANTLR.Tree.ASTNode' from assembly 'NHibernate, Version=2.1.2.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4' does not have an implementation.

which is also referred here . Below is all that i have in my console application, could you point out what is wrong

            ISessionFactory factory = CreateSessionFactory();

            //read using HQL the 500 users
            using (ISession dbSession = factory.OpenSession())
            {
                var users = dbSession.CreateQuery("from user").List();
            }

Dropbox Link to Solution ( Source + Database + Configuration ]

https://dl.dropboxusercontent.com/u/29815170/HQL.zip

note: Please do change your database connections inside the code

I would almost for sure say, that this is the lower/upper case issue. The HQL parser (the ANTLR engine) results in case sensitive statements. Because, in C# we use Pascal style for Class names, I would say that your class is User .

HQL is working on top of Entity/C# model. So this should/must be working:

var users = dbSession.CreateQuery("from User").List(); // U is in capital

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM