Coming from ibatis, so new, but stumped on how to set this up (multiple collections )
posted 8 years ago
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.