WHY THIS CODE:
StringBuffer queryString = new StringBuffer();
queryString.append("select lr.id, count(lre.leadingRecord) ");
queryString.append("from LeadingRecord lr ");
queryString.append("left outer join lr.leadingRecordErrors lre ");
queryString.append("group by lr.id ");
queryString.append("order by lr.id asc");
Session session = HibernateUtilSUNCE.getSession();
try {
Query query = session.createQuery(queryString.toString());
query.list();
}...
GENERATE FOLLOWING SQL:
select
leadingrec0_.ID as col_0_0_,
count(leadingrec1_.LRER_LDRE_ID) as col_1_0_
from
LEADING_RECORD leadingrec0_,
LEADING_RECORD_ERROR leadingrec1_,
LEADING_RECORD leadingrec2_
where
leadingrec0_.ID=leadingrec1_.LRER_LDRE_ID(+)
and
leadingrec1_.LRER_LDRE_ID=leadingrec2_.ID
group by
leadingrec0_.ID
order by
leadingrec0_.ID asc
INSTEAD DESIRED SQL GENERATED BY HIBERNATE TOOLS HQL EDITOR:
select
leadingrec0_.ID as col_0_0_,
count(leadingrec1_.LRER_LDRE_ID) as col_1_0_
from
LEADING_RECORD leadingrec0_,
LEADING_RECORD_ERROR leadingrec1_
where
leadingrec0_.ID=leadingrec1_.LRER_LDRE_ID(+)
group by
leadingrec0_.ID
order by
leadingrec0_.ID asc
SO I GET RESULT SET SOMETHING LIKE THIS:
[2003,2]
INSTEAD DESIRED ONE LIKE:
[2000,0]
[2001,0]
[2002,0]
[2003,2]
[2004,0]
|