-->
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: HQL and classcast excpetion
PostPosted: Tue Sep 21, 2010 6:06 pm 
Newbie

Joined: Tue Sep 21, 2010 1:31 pm
Posts: 5
Hi: I am using HQL to retrieve a graph of object but getting classcast exception.

Class A {
Set<B> b
Set<C> c
}

List <A> result = session.createQuery("from A a left outer join a.b where a.id = 1234").list();

I am using Hibernate 3.3.2 with JDK 1.6. Can some shed some light what could be the reasons.

Regards,
RJ.


Top
 Profile  
 
 Post subject: Re: HQL and classcast excpetion
PostPosted: Wed Sep 22, 2010 3:17 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
I think you need to specify 'select a from A a ....' otherwise the default is to include joined entities as well. The query you posted is the same as 'select a, b from A a ...' which is returned as a List<Object[]>.


Top
 Profile  
 
 Post subject: Re: HQL and classcast excpetion
PostPosted: Wed Sep 22, 2010 10:34 am 
Newbie

Joined: Tue Sep 21, 2010 1:31 pm
Posts: 5
Thanks borg for the response and the query worked like you suggested.

But I also able to make it work by doing this (see the code below), note the use of key word "fetch"; and I wonder is there any difference between the 2 approaches. If I picked it right from Hibernate reference document fetch forced an outer join and try to fetch all the records with a single select.

("from A a left outer join fetch a.b where a.id = 1234").list()


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.