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????
|