-->
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.  [ 2 posts ] 
Author Message
 Post subject: Class Cast Exception-Please help
PostPosted: Wed Jan 30, 2008 4:08 am 
Newbie

Joined: Wed Jan 30, 2008 3:38 am
Posts: 2
I'm using the following versions:

Eclipse Platform Version: 3.3.1.1 Build id: M20071023-1652

Hibernate Version :
Hibernate version: hibernate-3.2.5.ga


Code:

List <Person> personList = session.createQuery("select person.id,person.name from Person person where person.id='100'").list();
                
for(int i=0;i<personList.size();i++){
     Person per = personList.get(i);
     System.out.println("The value of Id is         : "+per.getId());
    }


I am Using Jdk 5 in my project..
When I execute the hibernate code above I am getting the class cast exception at.

Code:

Person per = personList.get(i);


Here is the exception:

java.lang.ClassCastException: [Ljava.lang.Object;

Another approach which I tried is:

Code:

List personList = session.createQuery("select person.id,person.name from Person person where person.id='100'").list();
                
for(int i=0;i<personList.size();i++){
     Person per = (Person)personList.get(i);
     System.out.println("The value of Id is         : "+per.getId());
    }



Even in this case I'm getting the same exception as above.

Please let me know if anybody had face the same situation and got resolved the issue.
Your help is highly appreciated.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 30, 2008 5:15 am 
Regular
Regular

Joined: Mon Aug 20, 2007 6:47 am
Posts: 74
Location: UK
Try

"select person from Person person where person.id='100'"

Your query was asking just for Id and Name so would not return a list of Person(s).


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.