title: Hibernate 3.6: registerFunction in SQL dialect not working
body: <p>I´m giving up and ask the community ...</p>
  
  <p>In my project, I´m using Hibernate 3.6.4.Final and a custom sql dialect:</p>
  
  <pre><code>public class ServiceAppMySQL5InnoDBDialect extends MySQL5InnoDBDialect {
  
      public ServiceAppMySQL5InnoDBDialect() {
          super();
          registerFunction("bitwise_and", new SQLFunctionTemplate(StandardBasicTypes.INTEGER, "(?1 &amp; ?2)"));
          registerFunction("hasflags", new SQLFunctionTemplate(StandardBasicTypes.BOOLEAN, "?1 &amp; ?2 = ?2"));
      }
  
  }
  </code></pre>
  
  <p>Using the <code>hasflags</code> method in a HQL query fails.
  Here is the query:</p>
  
  <pre><code>Query q = em
          .createQuery(
              "SELECT o FROM "
              + entityClass.getName()
              + " o WHERE hasflags(o.status, :status) AND o.email = :email")
          .setParameter("email", username)
          .setParameter("status", status.getBitmask());
  </code></pre>
  
  <p>The error:</p>
  
  <pre><code>Caused by: org.hibernate.hql.ast.QuerySyntaxException: unexpected AST node: ( near line 1, column 50 [SELECT o FROM tv.px.domain.Owner o WHERE hasflags(o.status, :status) AND o.email = :email]
      at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:54)
      at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:47)
      at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:82)
      at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:261)
      at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:185)
      at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
      at org.hibernate.engine.query.HQLQueryPlan.&lt;init&gt;(HQLQueryPlan.java:101)
      at org.hibernate.engine.query.HQLQueryPlan.&lt;init&gt;(HQLQueryPlan.java:80)
      at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:124)
      at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:156)
      at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:135)
      at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1770)
      at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:272)
  </code></pre>
  
  <p>So, it seems as if the function is not properly registered. I´ve done this several times with older Hibernate versions and it worked this way all the time. </p>
  
  <p>Just in case someone asks this: yes, I configured Hibernate to use the dialect:</p>
  
  <pre><code>&lt;persistence-unit name="persistenceUnit"
      transaction-type="RESOURCE_LOCAL"&gt;
      &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;
      &lt;properties&gt;
          &lt;property name="hibernate.dialect" value="tv.px.persistence.hibernate.ServiceAppMySQL5InnoDBDialect" /&gt;
  
          &lt;!-- and so on --&gt;
      &lt;/properties&gt;
  &lt;/persistence-unit&gt;
  </code></pre>
  
  <p>Edit: In the SELECT clause I can use registered functions without problems, but not in the WHERE clause.</p>