Yashnoo wrote:
Hi friends
I want to know if it is possible retrieve one parent and only one child in on HQL.
I mean that I want to get a child and a parent in one sql .
I try this:
Code:
select p.parentName,c.childName,elements(p.childSet).get(0) from Parent p,Child c
But it can't parse compile. Hibernate's HQL is object SQL, So I think it maybe work in this way,right?
If someone know how to do it ,please tell me , Thks!
That seems like the hard way to do it. If you have a backpointer from Child to Parent e.g. a many-to-one from child to parent, and that is mapped to the 'parent' property of child, you can do this:
Code:
select c.childName, c.parent.parentName from Child c
or even:
Code:
from Child c
and then use Java code in your application to access the properties, e.g.
Code:
Child c = ... get result from the above query ...
String x = c.getParent().getParentName();
String y = c.getChildName();