我正在尝试将我们最大的项目之一从NHibernate 2.1更新到最新版本3.3,并且遇到了以前工作正常的查询现在抛出Antlr.Runtime.MismatchedTokenException
错误的问题。
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。据我所知和谷歌搜索能力,这应该没问题。怎么了?
答案 0 :(得分:3)
我刚刚找到答案...查询已and
,应该说where
:
select count(a.Student)
from ExpiringAccessArrangement a
WHERE a.Student.IsAttending = 1
我真的不知道为什么那样有效,永远......!