Nhibernate 这个hql查询有什么问题,我在hql中使用fetch来重载子集合 string hql=“从客户处作为c左外部连接获取c.订单” +“其中c.CustomerId=:id”; 使用(会话) { return Session.CreateQuery(hql).SetInt32(“id”,id).List(); }
当我执行代码时,会出现如下异常: 通过FetchTest加载CustomerBydt: FailedNHibernate.Hql.Ast.ANTLR.QuerySyntaxException失败: 引发类型为“Antlr.Runtime.MismatchedTokenException”的异常。 在第1行第1列附近 56在 NHibernate.Hql.Ast.ANTLR.ErrorCounter.ThrowQueryException()在 NHibernate.Hql.Ast.ANTLR.HqlParseEngine.Parse()在 NHibernate.Hql.Ast.ANTLR.ASTQueryTranslatorFactory.CreateQueryTranslators(字符串 queryString,字符串集合角色,布尔浅值,IDictionaryNhibernate 这个hql查询有什么问题,我在hql中使用fetch来重载子集合 string hql=“从客户处作为c左外部连接获取c.订单” +“其中c.CustomerId=:id”; 使用(会话) { return Session.CreateQuery(hql).SetInt32(“id”,id).List(); },nhibernate,hql,fetch,Nhibernate,Hql,Fetch,当我执行代码时,会出现如下异常: 通过FetchTest加载CustomerBydt: FailedNHibernate.Hql.Ast.ANTLR.QuerySyntaxException失败: 引发类型为“Antlr.Runtime.MismatchedTokenException”的异常。 在第1行第1列附近 56在 NHibernate.Hql.Ast.ANTLR.ErrorCounter.ThrowQueryException()在 NHibernate.Hql.Ast.ANTLR.H
2
过滤器,ISessionFactoryImplementor工厂)在
NHibernate.Engine.Query.HQLStringQueryPlan.CreateTranslators(字符串
hql,字符串集合角色,布尔浅值,IDictionary
2
启用筛选器,ISessionFactoryImplementor工厂)在
NHibernate.Engine.Query.HQLStringQueryPlan..ctor(字符串hql,字符串
collectionRole,布尔浅层,IDictionary2个EnabledFilter,
ISessionFactoryImplementor工厂)在
NHibernate.Engine.Query.HQLStringQueryPlan..ctor(字符串hql,布尔值
浅显,IDictionary
2个启用的筛选器,ISessionFactoryImplementor
工厂)在
NHibernate.Engine.Query.QueryPlanCache.GetHQLQueryPlan(字符串
查询字符串、布尔浅值、IDictionary`2启用筛选器)在
NHibernate.Impl.AbstractSessionImpl.GetHQLQueryPlan(字符串查询,
布尔值(浅)在
NHibernate.Impl.AbstractSessionImpl.CreateQuery(字符串查询字符串)在
Data.NhibernateSample.热切加载CustomerBydthroughfetch(Int32 id)位置
DelayLoadTest.cs:第80行在
NhibernateDataAcessTest.NhibernateSampleFixture.WangeLoadCustomerBydthroughFetchTest()
位置 LazyLoad.cs:第73行
我的代码有什么问题,谢谢你你的SQL格式不正确,在“…c.Orders”+“where…”之间没有空格。我感谢你的回答。我修改了我的代码,然后异常消失,测试成功,谢谢你的帮助
string hql = "from Customer as c left outer join fetch c.Orders"
+ "where c.CustomerId=:id";
using(Session)
{
return Session.CreateQuery(hql).SetInt32("id",id).List<Customer>();
}