title: Using custom dialect function in hibernate @Formula
body: <p>I defined my custom dialect for HSQLDB:</p>
  
  <pre><code>public class CustomHSQLDialect extends HSQLDialect {
  
      public CustomHSQLDialect () {
          super();
          registerFunction("datediffsec", new SQLFunctionTemplate(
                  StandardBasicTypes.DOUBLE, "cast((?1 - ?2) AS INTERVAL SECOND)"));
      }
  }
  </code></pre>
  
  <p>I defined configuration:</p>
  
  <pre><code>hibernate.dialect=custom.dialect.CustomHSQLDialect 
  </code></pre>
  
  <p>Then I'm trying to use it in @Formula:</p>
  
  <pre><code>@Formula("case status when 'ACTIVE' then datediffsec(now(), creationDateTime) when 'CLEARED' then datediffsec(clearedDateTime, creationDateTime) end")
  </code></pre>
  
  <p>But I catch exception:</p>
  
  <blockquote>
    <p>Caused by: java.sql.SQLSyntaxErrorException: user lacks privilege or
    object not found: DATEDIFFSEC</p>
  </blockquote>
  
  <p>What I do wrong?</p>