2011-11-03 71 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