-->
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.  [ 6 posts ] 
Author Message
 Post subject: HQL With Select vs Without
PostPosted: Wed Dec 20, 2006 2:31 pm 
Newbie

Joined: Mon Dec 05, 2005 4:22 pm
Posts: 8
Lets say I have the following 2 HQL's:

FROM Cat c WHERE c.id > :id

This should return me a List with a list with Cat objects right?

Now lets say I have

SELECT c.Name FROM Cat c WHERE c.id > :id

I should recieve a list with Cat objects, but only the Name member is populated.

Correct?

Because what is happening with me is... When I use the select clause, I get a list of straight up Objects. NOT Cat objects... objects of type Object.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 20, 2006 3:01 pm 
Newbie

Joined: Wed Nov 02, 2005 1:17 pm
Posts: 13
You must cast the elements of the returned list to Cat

Query q = session.createQuery("from Cat c....");
List result = q.list();
for (Iterator iter = result.iterator(); iter.hasNext();) {
Cat nextCat = (Cat) iter.next();
// do something...
}


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 20, 2006 3:13 pm 
Newbie

Joined: Mon Dec 05, 2005 4:22 pm
Posts: 8
Ya, that is what I thought... but I am getting a ClassCastException

:(


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 20, 2006 3:16 pm 
Newbie

Joined: Mon Dec 05, 2005 4:22 pm
Posts: 8
Ofcourse, it isn't a Cat that I am dealing with. But the data I am trying to pull is sensitive. So I can't show it here. :(


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 20, 2006 3:16 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
they are Strings most likely, I'm guessing the name

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 21, 2006 1:51 am 
Newbie

Joined: Tue Dec 19, 2006 11:05 am
Posts: 11
In this case hibernate would return a String object not a cat.
Note that if you select more than one property from car you will get back an object array...


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