-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: ClassCastException with DOM4J
PostPosted: Wed Feb 08, 2006 7:41 am 
Newbie

Joined: Wed Feb 08, 2006 6:17 am
Posts: 9
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();

}
}


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 08, 2006 2:48 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
this is probably an array of elements, where did you find this exact offending code?

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Re: ClassCastException with DOM4J
PostPosted: Wed Feb 08, 2006 3:51 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
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()

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.