0
我試圖將我們最大的項目之一從NHibernate 2.1更新到最新版本3.3,並且遇到以前運行良好的查詢現在拋出Antlr.Runtime.MismatchedTokenException
錯誤的問題。Antlr.Runtime.MismatchedTokenException使用NHibernate 3.3
的HQL:
select count(a.Student)
from ExpiringAccessArrangement a
and a.Student.IsAttending = 1
兩個實體類(簡化本示例):
public class Student {
public virtual int StudentRef { get; set; }
public virtual string Surname { get; set; }
public virtual string Forename { get; set; }
public virtual bool IsAttending { get; set; }
/* other properties */
}
public class ExpiringAccessArrangement {
public virtual Student Student { get; set; }
public virtual DateTime DateAdded { get; set; }
/* other properties */
/* equality members */
}
的映射(同樣,簡化了該實施例中):
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="OurProduct.Model" namespace="OurProduct.Model.Core">
<class name="Student" table="Students">
<id name="StudentRef" column="Student_Ref" unsaved-value="0">
<generator class="assigned" />
</id>
<property name="Surname" />
<property name="Forename" />
<property name="IsAttending" formula="(CASE Enrolled_Code WHEN 4 THEN 1 ELSE 0 END)" />
<!-- other properties -->
</class>
</hibernate-mapping>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="OurProduct.Model" namespace="OurProduct.Model.Core">
<class name="ExpiringAccessArrangement" table="NonDefaultSchemaNameHere.Expiring_Access_Arrangements">
<composite-id>
<key-many-to-one name="Student" class="OurProduct.Model.Core.Student" column="Student_Ref" />
<key-property name="DateAdded" column="Date_Added" />
</composite-id>
<!-- other properties -->
</class>
</hibernate-mapping>
拋出的異常是:
Type: NHibernate.Hql.Ast.ANTLR.QuerySyntaxException
Message: Exception of type 'Antlr.Runtime.MismatchedTokenException' was thrown. near line 4, column 24
Source: NHibernate
Target site: Void ThrowQueryException()
Stack trace:
at NHibernate.Hql.Ast.ANTLR.ErrorCounter.ThrowQueryException()
at NHibernate.Hql.Ast.ANTLR.HqlParseEngine.Parse()
at NHibernate.Hql.Ast.ANTLR.ASTQueryTranslatorFactory.CreateQueryTranslators(String queryString, String collectionRole, Boolean shallow, IDictionary`2 filters, ISessionFactoryImplementor factory)
at NHibernate.Engine.Query.HQLStringQueryPlan..ctor(String hql, 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)
也許這是一件簡單的事情,但我所做的所有事情,正如我上面所說的,正在轉向更新版本的NHibernate。據我所知和谷歌搜索能力,這應該沒問題。怎麼了?
有一個類似的問題,但我有一個「where」和一些「ands」,但最後一個「和」是一個嵌套選擇。我將該嵌套select移至「where」之後,然後將其餘部分放入其中,然後修復它。奇怪的。你的回答給了我一些嘗試 - 所以謝謝你。 – Graham
已經很長時間了,但如果這對你有用,你應該接受這個答案! – Tophandour
@Tondndour你說得對,我應該有。現在完成,感謝提醒。 –