Can anyone help me with simple crap?
I have many-to-one relation, Objects (parent) with really huge list of childs. Now when i do select of one particular child, hibernate is selecting also a parent. And becouse parent have many childrens, i get also many childrens.
But i want only this one child without a parent and others. What to do? Sure I can ingore other that but when list have 1000+ elements that is huge waste.
You can configure the parent property in child class to be lazy loaded, that way it won't be loaded automatically...
Wojtek Baczyński
Greenhorn
Joined: Jul 28, 2010
Posts: 3
posted
0
Ankit thanks for your help but i've tried putting lazy="true" into many wird places and it never helps so could you be more specific? Please look at my simple files:
Site is parent and it have fields: Id, Name
Alias id child and it have: Id, SiteId, Name
So i don't know how to put lazy properitie to Alias file. I have lazy="true" in "<bag ..." in parent but it didn't seem to make any difference.
Tell me what should I change?
Ran Pleasant
Ranch Hand
Joined: Jan 16, 2003
Posts: 75
posted
0
Wojtek Baczyński wrote:Can anyone help me with simple crap?
I have many-to-one relation, Objects (parent) with really huge list of childs. Now when i do select of one particular child, hibernate is selecting also a parent. And becouse parent have many childrens, i get also many childrens.
But i want only this one child without a parent and others. What to do? Sure I can ingore other that but when list have 1000+ elements that is huge waste.
This is actually a common design problem that is a performance killer. In select cases a child object does need to have a reference to its parent object. However, in the majority of cases there is not a *real* need for a child object to have a reference to the parent object. Circilar references between classes can also set you up for an endless loop. I would suggest taking a step back from your code, reviewing your design, and ask yourself if the child object really does needs a reference to the parent object.
Ran
Wojtek Baczyński
Greenhorn
Joined: Jul 28, 2010
Posts: 3
posted
0
I think child don't need reference to parent at all. Simple ID (Foreign Key) would do the trick. But i thought that this lauzy reference is required to do one-to-many relation.
Clearly i don't like DB at all so forgive me if i am being noob.
I found something like solution i think. When i did that:
Then I got two select's, one with all aliases from site and one with site.
But if i changed it that way:
It gives only select to alias.
alias.ToString() is ovveriden by me and it is printing also parent field Site.Name
In second code which i pasted i of course got exception that I can't get into Site couse of lazy loading.
So it is kinda solution, i got only alias without site and other aliases.
rakesh kanchalwar
Greenhorn
Joined: Jul 29, 2010
Posts: 1
posted
0
Wojtek Baczyński wrote:Can anyone help me with simple crap?
I have many-to-one relation, Objects (parent) with really huge list of childs. Now when i do select of one particular child, hibernate is selecting also a parent. And becouse parent have many childrens, i get also many childrens.
But i want only this one child without a parent and others. What to do? Sure I can ingore other that but when list have 1000+ elements that is huge waste.