2011-11-03 48 views
0

以下是我的HQL查询。HQL查询的问题

delete from Table t 
where 
    (t.column1=:value1 and t.column2=:value2) 
    or (t.column3=:value3 and t.column4=:value4) 

当我运行此查询时,它会生成以下SQL,这是错误的。

delete from Table t 
where 
    t.column1=? 
    and t.column2=? 
    or t.column3=? 
    and t.column4=? 

在生成的SQL中删除了括号,这给出了错误的结果。

请帮忙。

回答

0

这不是一个结构化的解决方案,而只是为了使事情工作。 u能PLZ试试这个

delete from Table t 
    where 
     1=1 AND (t.column1=:value1 and t.column2=:value2) 
     or (t.column3=:value3 and t.column4=:value4) 

我天玑已经休眠安装在momenet,但我相信,一旦这个问题来找我,我决心像这样(我猜是这样)

NHibernate HQL logic problem

https://hibernate.onjira.com/browse/HHH-550

通过这些链接后,我发现(这可能是错误的),Hibernate正在完美地翻译这些查询。 “AND”具有更高的优先级,所以查询的结果应该完全不受影响......可能有其他一些原因

+0

Nopes。它不工作。 :( – ashishjmeshram

+0

@Ashish通过上述链接可能会帮助 – Zohaib

+0

@Ashish我在sql中测试了查询,qith括号并且没有括号,它给出了相同的结果,上面的链接中的解释是完美的。 – Zohaib