代码之家  ›  专栏  ›  技术社区  ›  Thomas Bratt

当使用相同术语的HQL select工作时,为什么这个HQL delete会失败?

  •  3
  • Thomas Bratt  · 技术社区  · 15 年前

    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();
    

    在select中使用相同的查询形式时也会起作用:

    string hql = @"from MyLog log
                   where
                        log.UtcTimestamp < :threshold and
                        log.Configuration.Application = :application";
    IList<MyLog> log = session.CreateQuery(hql)
        .SetDateTime("threshold", threshold)
        .SetEnum("application", this.application)
        .List<MyLog>();
    

    References(x => x.Configuration)
         .Columns("CONFIGURATION_ID")
         .ReadOnly();      
    

    配置映射包含:

    Map(x => x.Application, "APPLICATION_ID");
    

    从MYLOG中删除,配置 和应用程序ID=:p1;:p0= 2010年10月4日17:15:52,:p1=7

    计数器con1_uwhere UTC_TIMESTAMP<?和 应用程序ID=?

    Oracle.DataAccess.Client文件。OracleException: 结束了

    3 回复  |  直到 10 年前
        1
  •  5
  •   Diego Mijelshon    15 年前

    delete MyLog log
    where log.id in
              (select l.id
               from MyLog l
               where l.UtcTimestamp < :threshold and
               and.Configuration.Application = :application)
    
        2
  •  3
  •   Thomas Bratt    15 年前

    http://docs.jboss.org/hibernate/stable/core/reference/en/html/batch.html#batch-direct

    没有连接,无论是隐式的还是显式的, 可以在批量HQL查询中指定。 子查询可用于 它们本身可能包含连接

        3
  •  2
  •   Bozho    15 年前

    语法是 DELETE FROM MyLog ....

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

    推荐文章