Reputation: 2381
I have some doubts on that how for instance @OneToMany
might be efficient. Let's assume object A have collections of B objects inside of it and that collection have 100k objects
class A {
List<B> b; //.size() == 100.000
...
}
Even I mark b to being fetch LAZY what would following pseudo-code do?
select from database object into A a;
a.b.add(new B());
If I'm correct, because I made an access to field it has to be loaded, yes? So just to make one insert I have downloaded 100k rows from DB?
Can anyone clarify my doubts?
Upvotes: 0
Views: 33
Reputation: 19002
Yes, you are right: all 100k rows will be loaded.
What to do?
I suppose that there is also a reverse relationship from B to A. In this case, to avoid the performance problem you persist the B instance, when A has his list of B not loaded. Alternatively you could make a native query.
Upvotes: 1