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

2 Answers 2

3

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

Sign up to request clarification or add additional context in comments.

2 Comments

yes, which will have values like ['Windows',30]. How can i get to this values?
if List<Object[]> 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 ;)
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).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.