0
爲什麼這個查詢不起作用HQL錯誤和可空領域
FROM WorkflowConfiguration
WHERE ((saReplacement IS NOT NULL) AND (:currentTime >= saReplacement.start) AND (saReplacement.end >= :currentTime)) OR
((hrmsAdminReplacement IS NOT NULL) AND (:currentTime >= hrmsAdminReplacement.start) AND (hrmsAdminReplacement.end >= :currentTime)) OR
((hrManagerReplacement IS NOT NULL) AND (:currentTime >= hrManagerReplacement.start) AND (hrManagerReplacement.end >= :currentTime)) OR
((payrollAdminReplacement IS NOT NULL) AND (:currentTime >= payrollAdminReplacement.start) AND (payrollAdminReplacement.end >= :currentTime))
但是這一次確實
FROM WorkflowConfiguration
WHERE (saReplacement IN (from WorkflowReplacement as replacement WHERE (:currentTime >= replacement.start) AND (replacement.end >= :currentTime))) OR
(hrmsAdminReplacement IN (from WorkflowReplacement as replacement WHERE (:currentTime >= replacement.start) AND (replacement.end >= :currentTime))) OR
(hrManagerReplacement IN (from WorkflowReplacement as replacement WHERE (:currentTime >= replacement.start) AND (replacement.end >= :currentTime))) OR
(payrollAdminReplacement IN (from WorkflowReplacement as replacement WHERE (:currentTime >= replacement.start) AND (replacement.end >= :currentTime)))
之所以它這麼久是saReplacement,hrmsAdminReplacement,hrManagerReplacement和payrollAdminReplacement都可以null,所以我放入一個檢查來確保它們不是null,因此該子句的其餘部分不會被執行。但由於某種原因,當我運行第一個查詢時,我沒有得到任何結果,但是如果我運行第二個查詢(效率低得多),我會得到所有預期結果。這是Hibernate的HQL中的錯誤還是我失去了主意?
嗯,我會盡力的明天!謝謝! – Zoidberg 2009-08-19 20:03:44
更高效,更易於閱讀,比我更好的查詢,謝謝! – Zoidberg 2009-08-20 11:23:25