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.

相关问答

更多

如何使用FB api获取推广的页面帖子(How to get promoted page posts using FB api)

没有简单的方法可以做到这一点,因为帖子和广告之间没有任何关联。 最简单的方法可能是请求帐户的所有广告素材及其object_story_id: /<VERSION>/act_<ACCOUNT_ID>/adcreatives?fields=object_story_id 然后请求帐户中的所有广告以及广告素材和参考是否匹配: /<VERSION>/act_<ACCOUNT_ID>/ads?fields=id,creative There is no simple way to do this as ...

当Facebook的FB.init完成时如何检测(How to detect when facebook's FB.init is complete)

2012年1月4日更新 看起来像你以前一样FB.init()刚刚调用FB依赖的方法(例如FB.getAuthResponse() ),因为现在FB.init()似乎是异步的。 将你的代码包装到FB.getLoginStatus()响应中似乎是检测API完全准备就绪的窍门: window.fbAsyncInit = function() { FB.init({ //... }); FB.getLoginStatus(function(response){ ...

Facebook网站集成 - > fb-login button vs fb-registeration?(Facebook site integration -> fb-login button vs fb-registeration?)

仅向未使用facebook登录的用户显示登录Facebook按钮。 你必须更精确,你有一个网站或一个Facebook应用程序,一些API函数的工作方式不同。 3.4。 冲突在您的流逻辑中,您无法在您的网站上登录尚未注册帐户的用户。 我建议摆脱寄存器,并使用自动注册和/或自动登录: 用户进入网站 未登录Facebook - 显示登录facebook按钮,登录后返回此处 在Facebook上登录 - 在站点中显示您自己的登录按钮(您也可以自动登录,如果您在数据库中找到他的电子邮件地址,并且他之前已接受...

获取我的FB页面的通知(Get notifications for my FB page)

你可以试试iOS的facebook sdk。 对于页面中的展示帖子,您可以通过Facebook对象请求$ {pageId} / feed。 这样的事情。 这是页面对象 。 [facebook requestWithGraphPath:@"pageId/feed" andDelegate:self]; 推送通知,您必须通过选中相同的$ {pageId} / Feed来检查服务器中是否每2分钟有一个新的Feed。 如果$ {pageId} / Feed中有新帖子,您可以将内容推送给粉丝。 从ipho...

如何使用graph api获取fb用户的fb发送者ID时区?(How can we get fb user's timezone with fb sender id using graph api?)

它对我有用,也许你的大部分用户与你在同一时区? 只是为了确保我们与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...

如何使用ruby fb_graph发布Facebook页面更新?(How to post Facebook Page updates using ruby fb_graph?)

您需要查看图API 页面的文档。 检查access_token字段manages_pages 。 您需要在extended_permission设置此选项。 这里的关键是获得正确的令牌。 文本字段中的标记可能在大多数时间不起作用。 您需要将GET请求发送到https://graph.facebook.com/YOUR_PROFILE_ID/accounts以获取正确的令牌。 好像你已经得到了正确的一个。 我以前用过koala宝石。 如此处发布。 page_graph = Koala::Facebo...

如何在通过javascript和FB.api下载Facebook帖子时做分页?(How can I do pagination when downloading facebook posts via javascript and FB.api?)

您需要了解如何处理异步JavaScript以及如何执行递归功能。 您正试图在异步API调用设置它之前使用“x”。 意思是,整个for循环在“x”甚至设置一次之前完成 - 因为API调用需要一段时间。 这里有一些快速代码,没有测试它,但它应该显示一个解决方案: var items = []; function apiCall(next) { FB.api(next, function (response) { for (var i = 0; i < response.data...

通过FB api创建一个新的FaceBook页面(Create a new FaceBook page via the FB api)

不幸的是,您无法使用任何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 FB.api('/ me / accounts')没有返回应用程序列表(Facebook FB.api('/me/accounts') is not returning list of applications)

你必须跟上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...

将评论放在fb页面上(Putting the comment on a fb page)

我得到了解决方案,我正在使用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.

相关文章

更多

jsf +seam

list如何转化为Blob字段呢 java.util.ArrayList cannot be cas ...

com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException:

WEB系统报以下的错,是为什么? Caused by: java.sql.BatchUpdateEx ...

seam+jsf问题

在前台使用jsf,有一个用jsf标签写的下拉列表框 这是jsf标签 &lt;h:selectOne ...

【第十章】集成其它Web框架 之 10.4 集成JSF ——跟我学spring3

Spring提供javax.faces.el.VariableResolver的两种实现Delegat ...

《EJB 3.0从入门到精通》扫描版[PDF]

中文名: EJB 3.0从入门到精通 作者: 朱俊成 李有军 王俊伟 图书分类 ...

最新问答

更多

获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)

我用Google搜索了一个解决方案。 “EnumDisplayModeProvider”是我自己设置网站的各种模式的枚举。 public EnumDisplayModeProvider GetDisplayModeId() { foreach (var mode in DisplayModeProvider.Instance.Modes) if (mode.CanHandleContext(HttpContext)) {

如何通过引用返回对象?(How is returning an object by reference possible?)

这相对简单:在类的构造函数中,您可以分配内存,例如使用new 。 如果你制作一个对象的副本,你不是每次都分配新的内存,而是只复制指向原始内存块的指针,同时递增一个也存储在内存中的引用计数器,使得每个副本都是对象可以访问它。 如果引用计数降至零,则销毁对象将减少引用计数并仅释放分配的内存。 您只需要一个自定义复制构造函数和赋值运算符。 这基本上是共享指针的工作方式。 This is relatively easy: In the class' constructor, you allocate m

矩阵如何存储在内存中?(How are matrices stored in memory?)

正如它在“熵编码”中所说的那样,使用Z字形图案,与RLE一起使用,在许多情况下,RLE已经减小了尺寸。 但是,据我所知,DCT本身并没有给出稀疏矩阵。 但它通常会增强矩阵的熵。 这是compressen变得有损的点:输入矩阵用DCT传输,然后量化量化然后使用霍夫曼编码。 As it says in "Entropy coding" a zig-zag pattern is used, together with RLE which will already reduce size for man

每个请求的Java新会话?(Java New Session For Each Request?)

你是如何进行重定向的? 您是否事先调用了HttpServletResponse.encodeRedirectURL()? 在这里阅读javadoc 您可以使用它像response.sendRedirect(response.encodeRedirectURL(path)); The issue was with the path in the JSESSIONID cookie. I still can't figure out why it was being set to the tomca

css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)

我认为word-break ,如果你想在一个单词中打破行,你可以指定它,这样做可以解决问题: .column { word-break:break-all; } jsFiddle演示。 您可以在此处阅读有关word-break属性的更多信息。 I think word-break, with which you can specify if you want to break line within a word, will do the trick: .column { word-break

无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)

我认为您忘记在分类时间内缩放输入图像,如train_test.prototxt文件的第11行所示。 您可能应该在C ++代码中的某个位置乘以该因子,或者使用Caffe图层来缩放输入(请查看ELTWISE或POWER图层)。 编辑: 在评论中进行了一次对话之后,结果发现在classification.cpp文件中错误地删除了图像均值,而在原始训练/测试管道中没有减去图像均值。 I think you have forgotten to scale the input image during cl

xcode语法颜色编码解释?(xcode syntax color coding explained?)

转到: Xcode => Preferences => Fonts & Colors 您将看到每个语法高亮颜色旁边都有一个简短的解释。 Go to: Xcode => Preferences => Fonts & Colors You'll see that each syntax highlighting colour has a brief explanation next to it.

在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)

你考虑过第三方拼写检查吗? 您可以将在C#中开发的自定义WinForms控件插入访问数据库吗? VB6控件怎么样? 如果你能找到一个使用第三方库进行拼写检查的控件,那可能会有效。 Have you considered a third party spell checker? Can you insert a custom WinForms controls developed in C# into an access database? What about a VB6 control? If

从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)

我有同样的问题,因为我在远程服务器上有两个图像,我需要在每天的预定义时间复制到我的本地服务器,这是我能够提出的代码... try { if(@copy('url/to/source/image.ext', 'local/absolute/path/on/server/' . date("d-m-Y") . ".gif")) { } else { $errors = error_get_last(); throw new Exception($err

从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))

我不确定我完全明白你在说什么。 你能编辑你的帖子并包含你正在做的Subversion命令/操作的特定顺序吗? 最好使用命令行svn客户端,以便容易为其他人重现问题。 如果您只是想获取文件的旧副本(即使该文件不再存在),您可以使用如下命令: svn copy ${repo}/trunk/moduleA/file1@${rev} ${repo}/trunk/moduleB/file1 其中${repo}是您的存储库的URL, ${rev}是您想要的文件的版本。 这将恢复该文件的旧版本,包括最高版本