1

How can i access the elements from the list created as below? I tried creating a class containing a String and an int and cast to it but it doesn't work.

 List SOList = iadao.getSession().createQuery("select a.sistemOperare, count(a.sistemOperare) from User a, IstoricAfisari b, Banner c, Advertiser d where b.bannerId = c.id and c.advertiserId = d.id and b.userId = a.id group by a.sistemOperare").list();

Thank you

Dan Dinu
  • 32,492
  • 24
  • 78
  • 114

2 Answers2

3

This produces a List of Object arrays -> List<Object[]>

M Platvoet
  • 1,679
  • 1
  • 10
  • 14
  • yes, which will have values like ['Windows',30]. How can i get to this values? – Dan Dinu Jun 23 '11 at 08:52
  • if `List` represents to complete result set, `Object[]` represents a row in the result set. So I guess you are able to figure out what the values of the object array are ;) – M Platvoet Jun 23 '11 at 08:55
3

Since the createQuery(HQL).list() returns a List matching the indexes of the selected fields:

List SOList = ...
for (Object obj : SOList) {
    Object[] fields = (Object[]) obj;
    System.out.println("sistemOperare = " + fields[0] + " (count = " + fields[1] + ")");
}

Would print the results from the query, if any. According to hibernate documentation I could find (Since I'm more used to creating criteria for objects I want and then use Java for the rest).

Yhn
  • 2,785
  • 2
  • 13
  • 10