为什么这个HQL删除失败,当HQL与相同条款的作品选择?
-
27-09-2019 - |
题
为什么下面的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();
在选择使用时查询的相同的形式工作的:
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>();
有MyLog的映射包含:
References(x => x.Configuration)
.Columns("CONFIGURATION_ID")
.ReadOnly();
有配置的映射包含:
Map(x => x.Application, "APPLICATION_ID");
我得到的错误是:
这MYLOG,配置删除 countercon1_其中UTC_TIMESTAMP <:P0 和APPLICATION_ID =:P1; :P0 = 04/10/2010十七点15分52秒,:P1 = 7
NHibernate.Exceptions.GenericADOException: 无法执行更新查询[SQL:
这MYLOG,配置删除 countercon1_其中UTC_TIMESTAMP <?和 APPLICATION_ID =?
] ---> Oracle.DataAccess.Client.OracleException: ORA-00933:SQL命令不能正常 结束
解决方案
尝试这种情况:
delete MyLog log
where log.id in
(select l.id
from MyLog l
where l.UtcTimestamp < :threshold and
and.Configuration.Application = :application)
其他提示
从以上提出的圣拉斐尔的链接:
HTTP://文档。 jboss.org/hibernate/stable/core/reference/en/html/batch.html#batch-direct
没有连接,隐式或显式的, 可以在大批量HQL语句进行指定。 子查询可以在使用 WHERE子句,其中的子查询 本身可以包含加入
的语法是DELETE FROM MyLog ....
有无注意,HQL删除不具有定义的荣誉级联(n)的休眠映射。
所以,你可以选择所有的实体和一个删除一个。
不隶属于 StackOverflow