• 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

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.
 
This tiny ad is suggesting that maybe she should go play in traffic.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic