• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to select child object without his parent

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tantummano please check your private messages for some administrative matter...
 
Ankit Garg
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?



 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Wojtek Baczyński
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.

 
Why am I so drawn to cherry pie? I can't seem to stop. Save me tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic