-->
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.  [ 4 posts ] 
Author Message
 Post subject: NewBie Help - ClassCast Exception
PostPosted: Tue Jul 12, 2005 3:03 am 
Newbie

Joined: Tue Jul 12, 2005 2:32 am
Posts: 3
Hibernate version: 3.0

String sqlQuery = "SELECT * FROM PRODUCT WHERE PRODUCT.ID = 1"
SQLQuery query =

ems.comm.model.hibernate.EMSPersistentManager.instance().getSession().createSQLQuery(sqlQuery);

List resultList = (List) query.list();

Product p = (Product) list.get(0);

I am getting a ClassCast exception when i fetch the found objects in the usual way, with casting.. This is the does not happen when i fetch other object using way above.

When I print out the object name it the object type is something like" Exception: [Ljava.lang.Object; ]"

How do we check for the OBJECT in the list returned ?

Thank you in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 12, 2005 5:26 am 
Newbie

Joined: Tue Jul 12, 2005 5:17 am
Posts: 9
Print yourObject.getClass().getName(). Or just set a breakpoint to see :-)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 12, 2005 5:39 am 
Newbie

Joined: Tue Jul 12, 2005 2:32 am
Posts: 3
Hi,

Sorrie for not making my questions clear. I did print and breakpoint to see the object. Its suppose to give me an product obj instead of just an Object .

Any otherways for me to determine what type of object it is?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 12, 2005 5:56 am 
Beginner
Beginner

Joined: Fri Feb 11, 2005 12:03 pm
Posts: 48
Location: Kiel, Germany
Hi,

I think if you do not define the class of the entity to be returned list() will always return a list of Object[] since Hibernate does not know that you want to get a Product object back.

Try
Code:
Object[] row = (Object[])  list.get(0);
for (int i=0;i<row.length;i++) {
  System.out.println(row[i]);
}


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