首页 \ 问答 \ JSF / EJB3避免了视图层中的延迟初始化异常(JSF / EJB3 avoiding lazy initialization exceptions in the view layer)

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
更新时间:2022-08-05 15:08

最满意答案

不幸的是,您无法使用任何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.

相关问答

更多
  • 没有简单的方法可以做到这一点,因为帖子和广告之间没有任何关联。 最简单的方法可能是请求帐户的所有广告素材及其object_story_id: //act_/adcreatives?fields=object_story_id 然后请求帐户中的所有广告以及广告素材和参考是否匹配: //act_/ads?fields=id,creative There is no simple way to do this as there ...
  • 2012年1月4日更新 看起来像你以前一样FB.init()刚刚调用FB依赖的方法(例如FB.getAuthResponse() ),因为现在FB.init()似乎是异步的。 将你的代码包装到FB.getLoginStatus()响应中似乎是检测API完全准备就绪的窍门: window.fbAsyncInit = function() { FB.init({ //... }); FB.getLoginStatus(function(response){ ...
  • 仅向未使用facebook登录的用户显示登录Facebook按钮。 你必须更精确,你有一个网站或一个Facebook应用程序,一些API函数的工作方式不同。 3.4。 冲突在您的流逻辑中,您无法在您的网站上登录尚未注册帐户的用户。 我建议摆脱寄存器,并使用自动注册和/或自动登录: 用户进入网站 未登录Facebook - 显示登录facebook按钮,登录后返回此处 在Facebook上登录 - 在站点中显示您自己的登录按钮(您也可以自动登录,如果您在数据库中找到他的电子邮件地址,并且他之前已接受您的申请) ...
  • 你可以试试iOS的facebook sdk。 对于页面中的展示帖子,您可以通过Facebook对象请求$ {pageId} / feed。 这样的事情。 这是页面对象 。 [facebook requestWithGraphPath:@"pageId/feed" andDelegate:self]; 推送通知,您必须通过选中相同的$ {pageId} / Feed来检查服务器中是否每2分钟有一个新的Feed。 如果$ {pageId} / Feed中有新帖子,您可以将内容推送给粉丝。 从iphone中的$ ...
  • 它对我有用,也许你的大部分用户与你在同一时区? 只是为了确保我们与get请求在同一页面上...您可以在此处找到Facebook的用户个人资料参考。 https://developers.facebook.com/docs/messenger-platform/user-profile 您必须使用用户的ID和应用的令牌向此网址发出获取请求。 "https://graph.facebook.com/v2.6/USER_ID?fields=first_name,last_name,profile_pic,loca ...
  • 您需要查看图API 页面的文档。 检查access_token字段manages_pages 。 您需要在extended_permission设置此选项。 这里的关键是获得正确的令牌。 文本字段中的标记可能在大多数时间不起作用。 您需要将GET请求发送到https://graph.facebook.com/YOUR_PROFILE_ID/accounts以获取正确的令牌。 好像你已经得到了正确的一个。 我以前用过koala宝石。 如此处发布。 page_graph = Koala::Facebook::G ...
  • 您需要了解如何处理异步JavaScript以及如何执行递归功能。 您正试图在异步API调用设置它之前使用“x”。 意思是,整个for循环在“x”甚至设置一次之前完成 - 因为API调用需要一段时间。 这里有一些快速代码,没有测试它,但它应该显示一个解决方案: var items = []; function apiCall(next) { FB.api(next, function (response) { for (var i = 0; i < response.data.leng ...
  • 不幸的是,您无法使用任何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.
  • 你必须跟上Facebook的最新动态:-) 这一变化于12月公布,并于3月6日生效: 从/ me / accounts /删除应用 我们将不再在图谱API中的/ me / accounts /下显示应用。 您可以通过点击/ me / applications / developer /访问用户是开发人员的应用程序列表。 https://developers.facebook.com/blog/post/2012/12/05/platform-updates--operation-developer-love ...
  • 我得到了解决方案,我正在使用GET请求,而是使用POST请求 post_id/comments?message=Test Comment. 它将返回新的评论ID。 I got the solution, i was using GET request , instead use POST request post_id/comments?message=Test Comment. It will return the new comment ID.

相关文章

更多

最新问答

更多
  • 如何检索Ember.js模型的所有属性(How to retrieve all properties of an Ember.js model)
  • maven中snapshot快照库和release发布库的区别和作用
  • arraylist中的搜索元素(Search element in arraylist)
  • 从mysli_fetch_array中获取选定的值并输出(Get selected value from mysli_fetch_array and output)
  • Windows Phone上的可用共享扩展(Available Share Extensions on Windows Phone)
  • 如何在命令提示符下将日期设置为文件名(How to set file name as date in command prompt)
  • 如何在Laravel 5.2中使用paginate与关系?(How to use paginate with relationships in Laravel 5.2?)
  • 从iframe访问父页面的id元素(accessing id element of parent page from iframe)
  • linux的常用命令干什么用的
  • Feign Client + Eureka POST请求正文(Feign Client + Eureka POST request body)
  • 怎么删除禁用RHEL/CentOS 7上不需要的服务
  • 为什么Gradle运行测试两次?(Why does Gradle run tests twice?)
  • 由于有四个新控制器,Auth刀片是否有任何变化?(Are there any changes in Auth blades due to four new controllers?)
  • 如何交换返回集中的行?(How to swap rows in a return set?)
  • 在android中的活动之间切换?(Switching between activities in android?)
  • Perforce:如何从Depot到Workspace丢失文件?(Perforce: how to get missing file from Depot to Workspace?)
  • Webform页面避免运行服务器(Webform page avoiding runat server)
  • 在ios 7中的UITableView部分周围绘制边界线(draw borderline around UITableView section in ios 7)
  • 内存布局破解(memory layout hack)
  • 使用Boost.Spirit Qi和Lex时的空白队长(Whitespace skipper when using Boost.Spirit Qi and Lex)
  • 我们可以有一个调度程序,你可以异步添加东西,但会同步按顺序执行吗?(Can we have a dispatcher that you can add things todo asynchronously but will be executed in that order synchronously?)
  • “FROM a,b”和“FROM a FULL OUTER JOIN b”之间有什么区别?(What is the difference between “FROM a, b” and “FROM a FULL OUTER JOIN b”?)
  • Java中的不可变类(Immutable class in Java)
  • bat批处理文件结果导出到txt
  • WordPress发布查询(WordPress post query)
  • 如何在关系数据库中存储与IPv6兼容的地址(How to store IPv6-compatible address in a relational database)
  • 是否可以检查对象值的条件并返回密钥?(Is it possible to check the condition of a value of an object and JUST return the key?)
  • 德州新起点计算机培训学校主要课程有什么?
  • GEP分段错误LLVM C ++ API(GEP segmentation fault LLVM C++ API)
  • “latin1_german1_ci”整理来自哪里?(Where is “latin1_german1_ci” collation coming from?)