I am working on an HQL hibernate query and a simplified version of the code is below:
List messages = new ArrayList();
Session session = getSession(false);
String hqlSelect = "select id, messageText, uId from Message where uId = :userId";
Query query = session.createQuery(hqlSelect);
query.setString("userId", userId);
messages = query.list();
Iterator it = messages.iterator();
while (it.hasNext()) {
System.out.println("message -> "+ ( ((Message) ((ArrayList) it.next()).get(0)).getMessageText()));
}
I am getting ClassCast exception inside the while loop when I try to type cast the iterator to ArrayList or to Message. I think iterator is coming back as Object.
Is there any way I have the result set (List) returned as an array list of Message classes?