将 OpenSessionInViewInterceptor 与 Hibernate 和 JSF 2 结合使用
我正在 Hibernate、Spring 和 JSF2 中仅使用注释构建应用程序。如何利用 Spring 中的 OpenSessionInViewInterceptor 来捕获可能在 bean 中打开的任何休眠会话?
我试图优雅地解决常见的“未能延迟初始化角色集合:your.Class.assocation 没有会话或会话已关闭”。尝试从另一个 POJO 中尚未初始化的 POJO 列表(由包含我要读取的项目对象列表的 DAO 检索的标签实体)读取时出现问题。我发现了这个:
http://www.paulcodding .com/blog/2008/01/21/using-the-opensessioninviewinterceptor-for-spring-hibernate3/
但未能在我的环境中使用它。
请提供详细的答案,因为互联网上充满了模糊的、无用的教程。如果提供了分步说明,我也将非常感谢替代解决方案。
I'm building an application in Hibernate, Spring and JSF2 using only annotations. How can I take advantage of OpenSessionInViewInterceptor found in Spring to catch any hibernate session that might open within a bean?
I'm trying to elegantly solve the common “failed to lazily initialize a collection of role: your.Class.assocation no session or session was closed.” problem when trying to read from a yet uninitialized list of POJOs inside another POJO (A Tag entity retrieved by a DAO that contains a List of Project objects I want to read). I've found this:
http://www.paulcodding.com/blog/2008/01/21/using-the-opensessioninviewinterceptor-for-spring-hibernate3/
but failed to make use of it in my environment.
Please provide a detailed answer, as the Internet is full of foggy, unhelpful tutorials. I'll also be greatful for an alternative solution, given a step-by-step instruction is provided.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实证明它非常简单,比拦截器、AOP 和互联网上可以找到的无数奇怪的东西简单得多。
将此片段(注意第二个 init-param 中的小注释)插入到您的 web.xml 中,以忘记所有的烦恼。
It turned out to be quite simple, much simpler than interceptors, AOP and the myriads of weirdness that can be found all over the internet.
Insert this snippet (mind my little comment in the second init-param) into your web.xml to forget all your woes.