angusrose wrote:
Dear All,
I'm currently returning XML from a Hibernate query. However, I have encountered a ClassCastException when runnning the following piece of code which I have taken from the hibernate website. Any suggestions as to how I overcome it?
Thanks in advance
Angus
List results = dom4jSession.createQuery("select strAddress , dtrCode from EntityPOJO").list();
System.out.println(results.size());
Iterator it = results.iterator();
while(it.hasNext()){
if(it.next() != null){
Element customer = (Element)it.next();
}
}
You're selecting two objects (strAddress and dtrCode) which in POJO mode will return an Object[] containing the two objects. I assume this works the same in DOM4J mode.
From your while loop, it appears you're looking for a Element named Customer in which case you should be selecting Customer.... not the attributes on Customer.
If you leave it as is, you need to change the code inside the while loop to deal with the Object[] that will be returned from the it.next()