Nhibernate 当具有相同术语的HQL select工作时,为什么HQL delete会失败?

Nhibernate 当具有相同术语的HQL select工作时,为什么HQL delete会失败?,nhibernate,fluent-nhibernate,hql,ora-00933,hql-delete,Nhibernate,Fluent Nhibernate,Hql,Ora 00933,Hql Delete,为什么以下HQL查询失败 string hql = @"delete MyLog log where log.UtcTimestamp < :threshold and log.Configuration.Application = :application"; session.CreateQuery(hql) .SetDateTime("threshold", t

为什么以下HQL查询失败

string hql = @"delete MyLog log
               where
                    log.UtcTimestamp < :threshold and
                    log.Configuration.Application = :application";

session.CreateQuery(hql)
       .SetDateTime("threshold", threshold)
       .SetEnum("application", this.application)
       .ExecuteUpdate();
配置的映射包含:

References(x => x.Configuration)
     .Columns("CONFIGURATION_ID")
     .ReadOnly();      
Map(x => x.Application, "APPLICATION_ID");
我得到的错误是:

从MYLOG、配置中删除 计数器CON1,其中UTC时间戳 Oracle.DataAccess.Client.OracleException: ORA-00933:SQL命令不正确 结束

语法是DELETE FROM MyLog

请记住,HQL delete不支持使用nhibernate映射定义的级联


因此,您可以选择所有实体并逐个删除它们。

从上面Rafael提交的链接:

没有连接(隐式或显式), 可以在批量HQL查询中指定。 子查询可用于 where子句,其中子查询 它们本身可能包含连接

试试这个:

delete MyLog log
where log.id in
          (select l.id
           from MyLog l
           where l.UtcTimestamp < :threshold and
           and.Configuration.Application = :application)

你能试试吗?或者呢?如果你使用+1,它也会震动。谢谢你,法菲尔。看起来问题可能是:“在批量HQL查询中,不能指定任何隐式或显式连接。子查询可以在where子句中使用,其中子查询本身可能包含连接。'感谢代码示例。我已经尝试了这两种方法,但我相信隐式连接是导致问题的原因。@Thomas the FROM在使用时确实是可选的。刚刚回到这个问题,您的答案第一次起作用:
delete MyLog log
where log.id in
          (select l.id
           from MyLog l
           where l.UtcTimestamp < :threshold and
           and.Configuration.Application = :application)