Reputation: 12831
I'm attempting to update one of our largest projects from NHibernate 2.1 to the latest version, 3.3 and am running into an issue where a query that previously worked fine now throws an Antlr.Runtime.MismatchedTokenException
error.
The HQL:
select count(a.Student)
from ExpiringAccessArrangement a
and a.Student.IsAttending = 1
The two entity classes (simplified for this example):
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 */
}
The mappings (again, simplified for this example):
<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>
The exception being thrown is this:
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)
Maybe this is a simple thing, but all I've done, as I said above, is move to a newer version of NHibernate. To the best of my knowledge and Googling ability, this should be fine. What's wrong?
Upvotes: 1
Views: 5257
Reputation: 12831
I've just found the answer... the query had and
where it should have said where
:
select count(a.Student)
from ExpiringAccessArrangement a
WHERE a.Student.IsAttending = 1
I have literally no idea why that worked, ever...!
Upvotes: 3