Lets say i have a complex obj -A that is a root of complexed objects graph. (this is a network device modeling)
I am using ORM , so the relation with NODE to NODE in the graph is lazy loading, means that all the objects that has relation to A will not be loaded, until get will be invoked.
The client connect to the server via webservice.
How can i overcome the problem of combination between lazy loading and webservice?
I mean that when the client ask for A i dont want to send the whole graph, only A and the first level, and when it will invoke getB go to the server again and bring B.
Is there any solution for this?
Sorry if i am not clear.
Probable solutions :
1) Depending upon the client who is going to invoke your web service:
If you own the application that is going to be the consumer of this web service then :
i) You can return only the immediate childrens
ii) And on request, issue request to your web service to deliver next level nodes etc..
iii) In this case you need to have a web service which accepts the root node as a parameter, thus if the root node is null, then deliver the first set of nodes, if getChildren is invoked on node1, then obtain the second level of childrens etc.
iv) In this case, you consumer needs some coding since it has to call the web service each time it is trying to navigate deeper into the structure.
2) If it is not your application that is going to consume this web service and if this web service is available for external clients where you dont have control then:
a) Using the ORM obtain the root nodes
b) Then iterate, and invoke the 'get' on all the nodes
c) And recursively, call 'get' for all the nodes until the last level, thus loading the whole datastructure into memory and return this object from the web service
d) If you dont want to do this kind of iterating & recursively invoking 'get' on all nodes, then turn off the lazy load feature for the pojo if your ORM supports.
e) Caution : Memory consumption may be high, so you have to opt for this solution based on how much amount of data will be there.
f) Alternatively, you can choose (at runtime) whether to load the complete object graph or load lazy depending on amount of data that is actually there while the web service is invoked.
3) Dont use the ORM for this purpose!, find out what is the exact data that have to be returned, write a SQL query retrieve all the data and populate them into a normal 'view' pojo, and return.
Sorry if I did not answer your question.