-->
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.  [ 7 posts ] 
Author Message
 Post subject: Parent Objects without Childs
PostPosted: Sun Apr 18, 2004 6:40 am 
Newbie

Joined: Sun Apr 18, 2004 6:22 am
Posts: 4
Location: Heidelberg / Germany
Hello,
i could not find any good answer to this. So i try it with a new topic.
I have two object as Parent and child.
One are PrinterGroups and the other are Printers under the Groups.
If i do a query on the PrinterGroups i also get all the Printers in
the ArrayList of PrinterGroups returned as ArrayList of PrinterGroups, wich is of course ok as the Printers are a Member of The Groups. As there are posibly quite a
number of PrinterGroups and quite a Lot of Printers in the Applicatoin im Looking for a Posibility to retreive only the PrinterGroups without the Printers.

I tried it with a SELECT pg.id, pg.name, pg.descr FROM my.PrinterGroup pg.
But then i get an ArrayList of Objects as Return Parameter of the query, as described in the Documentation.
Is there a way to get something like an ArrayList of PrinterGroups where the Attribute Printers is null, Or do i have to create this manually after doing the query?

thanks for your help.

regards Ingo


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 18, 2004 6:51 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
use lazy="true" for the child collection, this will only load the collection content when it is first accessed.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 18, 2004 7:35 am 
Newbie

Joined: Sun Apr 18, 2004 6:22 am
Posts: 4
Location: Heidelberg / Germany
Hi michael,
thanks for the quick answer. I allready tried it and ether i am doing something wrong or this is not the way to do it.
i did put the lazy="true" in the list of printers in printergroup.hbm.xml
if i do call my junit tests an inside the Tests i Iterate over the PrinterGroups and wirte the attributes to the console i get an

Failed to lazily initialize a collection - no session or session was closed

exception, because then he his trying to read the Reports of that group.

I do understand what happens. The Problem is that i have a class
wich opens a session, queries the PrinterGroups, closes the sessions
and return the PrinterGroups to my Unittest class.

When i query for all PrinterGroups i only want to show a list of availiable
PrinterGroups with name and description. I do not care about the Printers at that moment.
If you click on one of the PrinterGroups i want to load a single PrinterGroup and in this Object
i certainly want to have all the associated printers already in.

Thanks again for your help.

greethings Ingo


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 18, 2004 8:08 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Well once you acces the list of printers, the session still has to be open, otherwise you get the exception you experienced. As long as you don't access the collection, it won't be loaded.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 18, 2004 9:03 am 
Newbie

Joined: Sun Apr 18, 2004 6:22 am
Posts: 4
Location: Heidelberg / Germany
Hi Michael,
thanks again. What you said is right. I think i had some coding in between
where i tried to access the ArrayList of Printers. Know i can retreive the attributes of the PrinterGroup without the Exception.

The Problem is that i shurely want to get all Printers within a PrinterGroup when i load a single PrinterGroup. If i do this the way i did set up the
System i get the Session Closes Exception, wich is obvious because the session is closed then.

I found two ways resolvind my problem

1. Take lazy="true" out of hbm.xml.
Create a Constructor in the PrinterGroup with id, name, desc as paramter.
Then query for
select new PrinterGroup(grp.id,grp.name,grp.desc) from ......
wich returns an ArrayList of PrinterGroups where the List of
Printers are null

or.

2. Leave the lazy="true" in the hbm.xml and do some extra work in the method where i load a single ReportGroup to be able to return
an allready complete ReportGroup with reports included before i close the
session. This is something i don't exactly know how to do. Can you give
me a hand on this?

wich way would you prefere?

cheers Ingo


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 18, 2004 9:04 am 
Newbie

Joined: Sun Apr 18, 2004 6:22 am
Posts: 4
Location: Heidelberg / Germany
Ups,
im trying to do the same thing with Reports, so please do not get confused when i mix Reports and Printers

thans Ingo


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 18, 2004 9:05 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Do 2. and use Hibernate.initialize() or left join fetch in a HQL query to initialize everything needed after the session is closed.


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