2014-03-05 61 views
0

我想執行這個HQL查詢:NHibernate的3.3.1.4000 HQL加入拋出一個異常ANTLR

"from Order as order join order.Services as services" 

,但任何時候我使用的是聯接我得到這個異常:

[QuerySyntaxException: Exception of type 'Antlr.Runtime.NoViableAltException' was thrown. near line 1, column 20] 
    NHibernate.Hql.Ast.ANTLR.ErrorCounter.ThrowQueryException() +118 
    NHibernate.Hql.Ast.ANTLR.HqlParseEngine.Parse() +490 
    NHibernate.Hql.Ast.ANTLR.ASTQueryTranslatorFactory.CreateQueryTranslators(String queryString, String collectionRole, Boolean shallow, IDictionary`2 filters, ISessionFactoryImplementor factory) +89 
    NHibernate.Engine.Query.HQLStringQueryPlan.CreateTranslators(String hql, String collectionRole, Boolean shallow, IDictionary`2 enabledFilters, ISessionFactoryImplementor factory) +88 
    NHibernate.Engine.Query.HQLStringQueryPlan..ctor(String hql, String collectionRole, Boolean shallow, IDictionary`2 enabledFilters, ISessionFactoryImplementor factory) +71 
    NHibernate.Engine.Query.HQLStringQueryPlan..ctor(String hql, Boolean shallow, IDictionary`2 enabledFilters, ISessionFactoryImplementor factory) +50 
    NHibernate.Engine.Query.QueryPlanCache.GetHQLQueryPlan(String queryString, Boolean shallow, IDictionary`2 enabledFilters) +241 
    NHibernate.Impl.AbstractSessionImpl.GetHQLQueryPlan(String query, Boolean shallow) +179 
    NHibernate.Impl.AbstractSessionImpl.CreateQuery(String queryString) +160 
    BL.Queue.GetOrders() in c:\Yayasoft\YTour\YTour\BL\Queues\Queue.cs:66 
    YTourWeb.Test.Page_Load(Object sender, EventArgs e) in c:\Yayasoft\YTour\YTour\YTourWeb\Test.aspx.cs:16 
    System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +51 
    System.Web.UI.Control.OnLoad(EventArgs e) +92 
    System.Web.UI.Control.LoadRecursive() +54 
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +772 

這發生在我添加連接(任何連接)時,如果我選擇了沒有連接的工作。
這兩個實體都被映射,所以它不是試圖加入未映射的屬性 任何想法的問題?

回答

2

在這種情況下,我會說,字order被錯誤地評估爲ORDER BY的一部分。嘗試使用不同的別名,例如orderX

var hql = "from Order as orderX join orderX.Services as services" 
+0

感謝它的工作原理, – user2968607

+0

大,NHibernate的享受;) –