sunny_dev
sunny_dev

Reputation: 755

What's wrong with this HQL? “Returning Null value for selecting an Entity in a join query"

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);

This query is giving valid values for ccrd.createdDate , but it is returning NULL for s1 entity. I have defined a one-to-one relation between CrComponentRelDependency & crComponentDependencyDtls.

Upvotes: 1

Views: 1129

Answers (1)

Bohemian
Bohemian

Reputation: 425083

HQL does all the joining for you, so don't explicitly join tables. Try this:

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

Note also the removal of unnecessary qualification and brackets from your HQL.

Upvotes: 1

Related Questions