2

这真的很困惑几个小时,我在互联网上搜索了很多,但没有找到可行的解决方案。有人可以指出问题出在哪里...谢谢!我创建了自己的方言课

public class MySQLDialectExtended : MySQLDialect
{
    public MySQLDialectExtended()
    {
        RegisterFunction("date_add_interval", new SQLFunctionTemplate(NHibernateUtil.Date, "date_add(?1, INTERVAL ?2 ?3)"));            
    }
}

然后我尝试按如下方式使用它:

query.Append(
   " ( date_add_interval(D.ApprovalDate, 1, YEAR) < current_timestamp() <  date_add_interval(D.RenewalDate, -1, YEAR) )");

它失败并出现以下异常:

NHibernate.Hql.Ast.ANTLR.QuerySyntaxException : Exception of type 'Antlr.Runtime.NoViableAltException' was thrown. near line 1, column 677

其中列号位于第一个“YEAR”单词的末尾。

编辑:这是我的配置

    <property name="dialect">MyCompanyName.MySQLDialectExtended, MyCompanyName</property>
    <property name="hbm2ddl.keywords">none</property>
4

1 回答 1

0

你能发布整个 NHibernate 查询吗?

更新:嗯,查询显然是格式错误和错误的:

Select distinct D from MBIgnition.Core.Domain.Model.Deal D where 1=1 and 
( (D.MortgageStatus = 30 ) or 
  (D.MortgageStatus = 35 ) or 
  (D.MortgageStatus = 40 ) or 
  (D.MortgageStatus = 45 ) or 
  (D.MortgageStatus = 55 ) or 
  (D.MortgageStatus = 50 ) ) and 
  // next line is erroneous as the first AND operator does not have a lefthand side operand
(( and ( date_add_interval(D.ApprovalDate, 1, YEAR) < current_timestamp() < date_add_interval(D.RenewalDate, -1, YEAR) ) ) )

如您所见,AND您的代码中有一个没有任何左侧参数的运算符。您的 HQL 应该有问题。再次仔细检查,如果您无法查明错误,在此处发布 HQL 或标准构建代码将很有用。

于 2010-04-17T12:19:22.033 回答