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>();
}
当我执行代码时,会出现这样的异常:
EagerLoadCustomerByIdThroughFetchTest: FailedNHibernate.Hql.Ast.ANTLR.QuerySyntaxException: 引发类型为“Antlr.Runtime.MismatchedTokenException”的异常。靠近第1行,列 56在NHibernate.Hql.Ast.ANTLR.ErrorCounter.ThrowQueryException()在 NHibernate.Hql.Ast.ANTLR.HqlParseEngine.Parse()在 NHibernate.Hql.Ast.ANTLR.ASTQueryTranslatorFactory.CreateQueryTranslators(字符串 queryString,String collectionRole,Boolean shallow,IDictionary
2 filters, ISessionFactoryImplementor factory) 在 NHibernate.Engine.Query.HQLStringQueryPlan.CreateTranslators(String hql, String collectionRole, Boolean shallow, IDictionary
2 enabledFilters,ISessionFactoryImplementor factory)在 NHibernate.Engine.Query.HQLStringQueryPlan..ctor(String hql,String collectionRole,Boolean shallow,IDictionary2 enabledFilters, ISessionFactoryImplementor factory) 在 NHibernate.Engine.Query.HQLStringQueryPlan..ctor(String hql, Boolean shallow, IDictionary
2 enabledFilters,ISessionFactoryImplementor 工厂)在 NHibernate.Engine.Query.QueryPlanCache.GetHQLQueryPlan(字符串 queryString,Boolean shallow,IDictionary`2 enabledFilters)在 NHibernate.Impl.AbstractSessionImpl.GetHQLQueryPlan(String query, 布尔浅)在 NHibernate.Impl.AbstractSessionImpl.CreateQuery(String queryString)在 Data.NhibernateSample.EagerLoadCustomerByIdThroughFetch(Int32 id)位置 DelayLoadTest.cs:第80行 NhibernateDataAcessTest.NhibernateSampleFixture.EagerLoadCustomerByIdThroughFetchTest() 位置LazyLoad.cs:第73行
我的代码有什么问题,谢谢
答案 0 :(得分:0)
您的SQL格式错误,以下内容之间没有空格:“... c.Orders”+“where where”。