-->
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: Unable to solve hql mystery
PostPosted: Sat Jun 26, 2004 8:17 am 
Beginner
Beginner

Joined: Sun Jun 20, 2004 11:39 pm
Posts: 24
Hi there,

I have got this query here:

String query="select elements(c.companyContactGroups) from User as u inner join u.companyGroups as compgs inner join compgs.company as c inner join fetch c.companyContactGroups as ccg inner join fetch ccg.contacts where u.id="+userId;

There are basically 2 questions i have here, the syntax of the query is correct and there are 2 fetch clauses in the query. basically, what i am aiming to accomplish is to fetch all company contact groups with its contacts children all at one go in a single query so that when i get a list of company contact groups, i can iterator through each contact group and get the contacts in each group after the session has closed.

1) However, even though i have used the fetch clause twice in the query, iterating through the comopany contact groups is not a problem, but the problem comes when i try to get the contacts in the contact group , i get a lazy initialization error, so what gives?

2)another thing: becos of the first problem mentioned above , i changed teh query to

String query="select ccg from User as u inner join u.companyGroups as compgs inner join compgs.company as c inner join fetch c.companyContactGroups as ccg inner join fetch ccg.contacts where u.id="+userId;

i think i am getting a list of company contact groups again , perhaps just a different way of specifying, but i got a class cast exception when i do
(CompanyContactGroup)iter.hasNext();

i have also tried to find out the class type so i did
System.out.println(iter.hasNext().getClass());

i got "Object"

any ideas anyone????


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 26, 2004 9:36 am 
Beginner
Beginner

Joined: Mon Jun 07, 2004 4:21 pm
Posts: 44
Location: Boston
For the second part of your question see if this helps:

http://forum.hibernate.org/viewtopic.php?t=932123


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 26, 2004 9:40 am 
Beginner
Beginner

Joined: Sun Jun 20, 2004 11:39 pm
Posts: 24
thanks for your reply, but i still dont understand why do i have to create new objects just to store the contact groups, and its not that i am retreiving multiple objects of different classes. i am trying to retrieve a list of objects of the same type (CompanyContactGroups) from which i will be able to retreive the contacts in those groups.

any comments ?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 26, 2004 10:02 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
As per the documentation, you may FETCH only one collection per query.


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.