Create list of objects from subselect in select with HQL
Is it possible to create a object hierarchy with non-entity objects and a 1:n relation from a HQL-Query?
Note: Creating Analysis objects, when ful开发者_运维技巧ly qualified with namespace is no problem. The only problem is the association via subselect to SubAnalysis objects.
Classes:
public class Analysis
{
public List<SubAnalysis> relatedAnalysis;
public Long someSum;
public Analysis(Long someSum, List<SubAnalysis> relatedAnalysis)
{
this.someSum = someSum;
this.relatedAnalysis= relatedAnalysis;
}
}
public class SubAnalysis
{
public String info;
public SubAnalysis(String info)
{
this.info = info;
}
}
HQL:
select new Analysis(sum(t.value),
(select new SubAnalysis(x.info)
from SomeTable x
where x.t = t))
from Table t
where t.id = :id
group by t
So i basically want to be able to generate a report in objects for the entities:
Table => SomeTable, SomeTable
Like:
Analysis => SubAnalysis, SubAnalysis
The real query involves a lot more summing and joining.
Creating the Analysis object should be possible, although I'm not sure if you'd have to use the FQCN, since Hibernate has to know the exact class to use. For the SubAnalysis objects and association, I'm not sure and the documentation doesn't explicitly tell us (or I'm just blind ;) ).
精彩评论