为什么这个HQL删除失败,当一个HQL选择相同的条款工作? [英] Why does this HQL delete fail, when an HQL select with same terms works?

查看:141
本文介绍了为什么这个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); 

我得到的错误是:


从MYLOG中删除,CONFIGURATION
countercon1_其中UTC_TIMESTAMP<:p0
和APPLICATION_ID =:p1; :p0 =
04/10/2010 17:15:52,:p1 = 7

NHibernate.Exceptions.GenericADOException:
无法执行更新查询[SQL:



从MYLOG中删除,CONFIGURATION
countercon1_ where UTC_TIMESTAMP< ?和
APPLICATION_ID =?



] --->
Oracle.DataAccess.Client.OracleException:
ORA-00933:SQL命令不正确
结束


解决方案

试试这个:

  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:

delete from MYLOG, CONFIGURATION countercon1_ where UTC_TIMESTAMP<:p0 and APPLICATION_ID=:p1; :p0 = 04/10/2010 17:15:52, :p1 = 7

NHibernate.Exceptions.GenericADOException: could not execute update query [SQL:

delete from MYLOG, CONFIGURATION countercon1_ where UTC_TIMESTAMP< ? and APPLICATION_ID= ?

] ---> Oracle.DataAccess.Client.OracleException: ORA-00933: SQL command not properly ended

解决方案

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选择相同的条款工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆