2012-04-06 46 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