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。我已经定义了CrComponentRelDependencycrComponentDependencyDtls之间的一对一关系。

4

1 回答 1

1

HQL 为您完成所有连接,因此不要显式连接表。尝试这个:

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

还要注意从 HQL 中删除不必要的限定和括号。

于 2012-04-06T13:30:25.170 回答