模块通过 EJB 公开功能.如何处理模块之间的 Hibernate 延迟加载? [英] Modules exposing functionality via EJBs. How to handle Hibernate lazy loading between modules?
问题描述
假设一个应用程序被分成多个模块,每个模块通过 EJB 公开功能.如果模块 A 调用模块 B 中的 EJB 方法,该方法返回通过 Hibernate 检索的对象,则模块 A 将无法调用该对象的延迟加载方法,因为会话不再存在.遇到这种情况怎么办?
我做出了这个最终决定.还没有尝试过,但我认为它会起作用.问题是
如果模块 A 调用模块 B 中的 EJB 方法,该方法返回通过 Hibernate 检索到的对象,则模块 A 将无法调用该对象的延迟加载方法,因为会话不再存在.>
所以为了克服这个问题,模块 B 将只返回对象的主键,模块 A 将通过 Hibernate 检索对象.这样模块 A 就可以调用对象的延迟加载方法了.
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?
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.
这篇关于模块通过 EJB 公开功能.如何处理模块之间的 Hibernate 延迟加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!