Lets say an application is broken into modules, each module exposing functionality via EJBs. If module A makes a call to an EJB method in module B which returns an object retrieved via Hibernate, then module A will not be able to call a lazy loading method of that object because the session is no longer there. How to handle this kind of situation?
问题:
回答1:
There are no alternatives but to fully hydrate an object before returning it from system B. Hibernate doesn't span JVMs and neither you want it to. If the object is too big then you might want to introduce two (or as many) calls to return summary and details.
回答2:
I came up with this final decision. Haven't tried it yet but I think it will work. The problem was
If module A makes a call to an EJB method in module B which returns an object retrieved via Hibernate, then module A will not be able to call a lazy loading method of that object because the session is no longer there.
So in order to overcome this, module B will return only the primary key of the object and module A will retrieve the object via Hibernate. This way module A will be able to call lazy loaded methods of the object.