• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Coming from ibatis, so new, but stumped on how to set this up (multiple collections )

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've been googling and could use some advice on how others deal with this. For sake of discourse imagine this Entity (only showing relevant for this example):



Basically sometimes I want everything (including children and company info), sometimes I do not need everything. My question is how to write the queries and set up the fetchTypes to accommodate the different scenarios? I'm not opposed to some n+1 since I understand it's not reasonable to expect it to be able to do multiple fetch joins, but the problem is I don't want to declare any of my fetchTypes EAGER since I don't always want the collection fetched, but if I leave it LAZY, then I'll end up with LazyInitialized exceptions if I'm detached and end up needing everything.

Is the approach to take when needing everything (using this as an example)..
1) get the Person back using the fetch join on Company
2) make another query to the Person entity to get children
3) call the setChildren setter on the parent person (from step1 ) with the children we just got

Thanks for any help in figuring the best practice for this kind of situation, which I would think would come up quite often. Sorry for such a basic question, but the books that I have don't seem to cover this.
 
I claim this furniture in the name of The Ottoman Empire! You can keep this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic