JSF / EJB3避免了视图层中的延迟初始化异常(JSF / EJB3 avoiding lazy initialization exceptions in the view layer)
我有以下JSF / PrimeFaces EJB架构:
[JSF / PrimeFaces xhtml视图] - > [@ManagedBean JSF bean] - > [@Stateless EJB3 bean] --JPA - > [DB]
也就是说,JSF视图显示它们在其支持bean( @ManagedBean )上访问的实体和集合,并且这些集合和实体依次通过调用注入了EntityManager的无状态EJB3 “facade”bean来获取,并使用JPA支持来访问数据库。 休眠 。 无状态EJB3 bean也提供了一些服务,但在大多数情况下,它们的作用是根据需要显示它们的xhtml视图的请求,从数据库中提供Entity对象( JPA -annotated)。
现在就是这样:如果我的理解是正确的,那么当无状态EJB3 bean返回Entity bean时,它们会在每个EJB3 bean方法划分事务时分离。 通常情况是,当xhtml视图和JSF Managed bean导航如此获取的Entity对象的图形(One-To-Many集合等)时,我经常得到如下的Lazy Initialization异常:
javax.el.ELException: ... org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: ..., no session or session was closed
唯一有效的是将集合更改为EAGER -ly加载,但这不是一个实用的解决方案。 当分离的JPA实体找到进入视图层的方式时,要使用哪些好的模式,以避免一劳永逸的延迟初始化异常,而不是必须以临时方式处理每个案例?
I have the following JSF/PrimeFaces EJB architecture:
[JSF/PrimeFaces xhtml view] --> [@ManagedBean JSF bean] --> [@Stateless EJB3 bean] --JPA--> [DB]
That is, the JSF views display entities and collections they access on their backing beans (@ManagedBean) and these collections and entities are in turn fetched by calling stateless EJB3 "facade" beans that have the EntityManager injected and access the database using JPA backed by Hibernate. The stateless EJB3 beans also provide some services but for the most part their role is to provide the Entity objects (JPA-annotated) from the database, as requested by the xhtml views that need to display them.
Now here's the thing: if my understanding is correct, the moment the Entity beans are returned by the stateless EJB3 beans, they become detached as each EJB3 bean method demarcates a transaction. It is then often the case that as the xhtml views and the JSF Managed beans navigate the graphs of the Entity objects so fetched (One-To-Many collections and such), I often get Lazy Initialization exceptions like the following:
javax.el.ELException: ... org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: ..., no session or session was closed
The only thing that works is changing collections to be EAGER -ly loaded but that's not a pragmatic solution. What are some good patterns to use when detached JPA entity find their way to the view layer in order to avoid once and for all the lazy initialization exceptions rather than having to treat each case in an ad-hoc manner?
原文:https://stackoverflow.com/questions/13089888
满意答案
不幸的是,您无法使用任何Facebook API创建页面。 您只能通过facebook.com上的用户界面执行此操作。
Unfortunately, you can't create pages with any of the Facebook APIs. You can only do this through the user interface on facebook.com.
相关问答
更多如何使用FB api获取推广的页面帖子(How to get promoted page posts using FB api)
当Facebook的FB.init完成时如何检测(How to detect when facebook's FB.init is complete)
Facebook网站集成 - > fb-login button vs fb-registeration?(Facebook site integration -> fb-login button vs fb-registeration?)
获取我的FB页面的通知(Get notifications for my FB page)
如何使用graph api获取fb用户的fb发送者ID时区?(How can we get fb user's timezone with fb sender id using graph api?)
如何使用ruby fb_graph发布Facebook页面更新?(How to post Facebook Page updates using ruby fb_graph?)
如何在通过javascript和FB.api下载Facebook帖子时做分页?(How can I do pagination when downloading facebook posts via javascript and FB.api?)
通过FB api创建一个新的FaceBook页面(Create a new FaceBook page via the FB api)
Facebook FB.api('/ me / accounts')没有返回应用程序列表(Facebook FB.api('/me/accounts') is not returning list of applications)
将评论放在fb页面上(Putting the comment on a fb page)
相关文章
更多jsf +seam
com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException:
seam+jsf问题
【第十章】集成其它Web框架 之 10.4 集成JSF ——跟我学spring3
《EJB 3.0从入门到精通》扫描版[PDF]
最新问答
更多获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
如何通过引用返回对象?(How is returning an object by reference possible?)
矩阵如何存储在内存中?(How are matrices stored in memory?)
每个请求的Java新会话?(Java New Session For Each Request?)
css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
xcode语法颜色编码解释?(xcode syntax color coding explained?)
在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
Copyright ©2023 peixunduo.com All Rights Reserved.粤ICP备14003112号
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们(neng862121861#163.com),本站将尽快处理。谢谢合作!