title: Antlr.Runtime.MismatchedTokenException using NHibernate 3.3
body: <p>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 <code>Antlr.Runtime.MismatchedTokenException</code> error.</p>
  
  <p>The HQL:</p>
  
  <pre><code>select count(a.Student)
  from ExpiringAccessArrangement a
  and a.Student.IsAttending = 1
  </code></pre>
  
  <p>The two entity classes (simplified for this example):</p>
  
  <pre><code>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 */
  }
  </code></pre>
  
  <p>The mappings (again, simplified for this example):</p>
  
  <pre><code>&lt;hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="OurProduct.Model" namespace="OurProduct.Model.Core"&gt;    
      &lt;class name="Student" table="Students"&gt;
          &lt;id name="StudentRef" column="Student_Ref" unsaved-value="0"&gt;
              &lt;generator class="assigned" /&gt;
          &lt;/id&gt;
          &lt;property name="Surname" /&gt;
          &lt;property name="Forename" /&gt;
          &lt;property name="IsAttending" formula="(CASE Enrolled_Code WHEN 4 THEN 1 ELSE 0 END)" /&gt;
          &lt;!-- other properties --&gt;
      &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  
  &lt;hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="OurProduct.Model" namespace="OurProduct.Model.Core"&gt;
      &lt;class name="ExpiringAccessArrangement" table="NonDefaultSchemaNameHere.Expiring_Access_Arrangements"&gt;
          &lt;composite-id&gt;
              &lt;key-many-to-one name="Student" class="OurProduct.Model.Core.Student" column="Student_Ref" /&gt;
              &lt;key-property name="DateAdded" column="Date_Added" /&gt;
          &lt;/composite-id&gt;
          &lt;!-- other properties --&gt;
      &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>The exception being thrown is this:</p>
  
  <pre><code>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)
  </code></pre>
  
  <p>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?</p>