java - Best ways to use the lazy load -


i have long chain of objects, of loaded lazily. use jpa(out of luck on fetchmodes)

in few cases dont have load full object graph, in these cases performance good. in few other cases, might have load full object graph below.

below classes representational purpose only

firstobject.java  @lazy private set<secondobject> 

secondobject.java     @lazy private set<thirdobject> // may load 20-30 objects @lazy private set<fourthobject> // may load 20-30 objects 

thirdobject.java @lazy private set<fourthobject> // may load 10 - 100 records 

fourthobject.java @lazy private set<fifthobject> // may load 10-100 records 

.
.
.
(the list goes on)

edge case

if see, each child loads several children , there no way avoid. imagine user trying load firstobject.java , needs full object graph until fifthobject.java graph.

firstobject = session.get(firstobject.class, 10); 

//because children lazy, tries initialize them below.

firstobject.getsecondobject().size() // size() load lazy children 

//now each of child collection , lazy has following

for(secondobject sec: firstobject.getsecondobject()){     sec.getthirdobject().size();    //because third object needs fourth object loop third , ffourth } 

all above code takes around 7-10 seconds run, , may more if children more.

question is, how load objects in case? user interaction erratic, may or may not need full graph.

i've thought using custom jpql/native sql joins related children , return entity objects 1 option, wondering if effort good.

note: user may not need information returned in object graph, but, needs couple of properties display purpose(but needs objects though).

i've thought using custom jpql/native sql joins related children , return entity objects 1 option, wondering if effort good.

i think option you. have summarize information somehow in database , minimize object creation in app. bringing these objects main memory perform calculation bad idea.

also, consider pre-calculating results, if they're expensive done, improve time response. example, if it's expensive calculate total, keep total somewhere else in db , increase/decrease on every inserted/deleted item.


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -