1)I would like to sort by rank which is created by a matematic operation of agregation functions. It is unable to create a alias. Hibernate reports: "unknown column rank"
Code:
String hql = "select company, (3*sum(broker.loginCount) + 15*sum(broker.contacts) + 5*sum(broker.alreadySeenCount)) as rank "
+ "from Company company join company.brokers broker " +
"group by broker.company.id " + "order by rank";
So I have to use
Code:
"order by col_1_0_ desc"
because of generated SQL (see below)
Code:
select
company0_.id as col_0_0_, 3*sum(brokers1_.loginCount)+15*sum(brokers1_.contacts)+5*sum(brokers1_.alreadySeenCount) as col_1_0_,
company0_.id as id1_,
from
Company company0_
inner join
AbstractUser brokers1_
on company0_.id=brokers1_.company_id
group by
brokers1_.company_id
order by
col_1_0_ desc limit ?
2) This query returns list of Object[] so I have to use terrible casting
Code:
Query query = session.createQuery(hql);
query.setMaxResults(maxResult);
List temp = query.list();
List<Company> bestPartners = new ArrayList<Company>();
for (int i = 0; i < temp.size(); i++) {
bestPartners.add((Company) ((Object[]) temp.get(i))[0]);
}
How could I get only list of Company?
(I use Hibernate 3.2.1.ga)