为什么这个HQL删除失败

为什么这个HQL删除失败

本文介绍了为什么这个HQL删除失败,当一个HQL选择相同的条款工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么下面的HQL查询失败?

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

session.CreateQuery(HQL)
.SetDateTime( 阈值,阈值)
.SetEnum( 应用程序,this.application)
.ExecuteUpdate() ;

在select中使用同样的查询形式:
$从MyLog日志
其中
log.UtcTimestamp<:threshold和
log.Configuration.Application = b
pre $ string hql = @ :应用;
IList< MyLog> log = session.CreateQuery(hql)
.SetDateTime(threshold,threshold)
.SetEnum(application,this.application)
.List< MyLog>

MyLog的映射包含:

引用(x => x.Configuration)
.Columns(CONFIGURATION_ID)
.ReadOnly();

Configuration的映射包含:

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

我得到的错误是:


解决方案

试试这个:

  delete MyLog log 
其中log.id在
中(从MyLog中选择l.id
l
where l.UtcTimestamp<:threshold and
and.Configuration.Application =:application)


Why does the following HQL query fail?

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

The same form of query works when used in a 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>();

The mapping for MyLog contains:

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

The mapping for Configuration contains:

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

The error I get is:

解决方案

Try this:

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

这篇关于为什么这个HQL删除失败,当一个HQL选择相同的条款工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 18:59