2012-04-06 45 views
1
session.createQuery("select ccrd.createdDate , s1 " 
+ "from CrComponentRelDependency ccrd " 
+ "left outer join ccrd.crComponentDependencyDtls s1 " 
+ "where ccrd.crComponent.componentSeq= :COMPONENT_SEQ " 
+ "and (ccrd.referencedComponentVer IS NULL) " 
.setParameter("COMPONENT_SEQ", componentId); 

此查詢給有效值ccrd.createdDate,但它是爲S1實體返回NULL。 我已經定義了一個以「爲連接查詢選擇實體返回空值」 crComponentDependencyDtls酮關係之間CrComponentRelDependency & 這個HQL有什麼問題?

回答

1

HQL爲您完成所有的加盟,讓不要明確加入表格。試試這個:

session.createQuery("select createdDate, crComponentDependencyDtls " 
+ "from CrComponentRelDependency ccrd " 
+ "where crComponent.componentSeq = :COMPONENT_SEQ " 
+ "and referencedComponentVer IS NULL") 
.setParameter("COMPONENT_SEQ", componentId); 

請注意從您的HQL中刪除不必要的資格和括號。

+0

嗨波西米亞,感謝您的建議。我嘗試了上面的查詢,但它總是會爲createdDate字段返回一個有效的日期,而爲第二個值返回null。我錯過了什麼嗎? – 2012-04-09 04:36:34

+0

您還沒有發佈足夠的信息讓我進一步提供幫助。事實上,我猜得最多。我不知道你的表格佈局是什麼,也不知道你有什麼數據。 – Bohemian 2012-04-09 12:41:45