最佳 Tomcat6 JNDI +用于会话/事务支持的 Hibernate 配置

发布于 2024-08-27 02:00:27 字数 676 浏览 4 评论 0原文

引用 hib 官方文档:

从版本 3.0.1 开始,Hibernate 添加了 SessionFactory.getCurrentSession() 方法。最初,假定使用 JTA 事务,其中 JTA 事务定义当前会话的范围和上下文。鉴于众多独立 JTA TransactionManager 实现的成熟度,大多数(如果不是全部)应用程序都应该使用 JTA 事务管理,无论它们是否部署到 J2EE 容器中。基于此,您只需要使用基于 JTA 的上下文会话即可。 引用结束

我使用tomcat6作为servlet容器,需要将Hibernate 3.2集成到项目中。

我找到了一个如何通过 JNDI 配置 SessionFactory 查找的文档,尽管它没有按预期工作。

引用: Hibernate 可以在任何使用 JTA 的环境中工作,事实上,我们建议尽可能使用 JTA,因为它是标准的 Java 事务接口。 报价结束。

在休眠配置中,我指示 current_session_context_class = jta

,现在我收到错误“未指定 TransactionManagerLookup”。

问题是 Tomcat 不支持 JTA,要让它工作, 如果我理解正确的话 您需要将 JOTM 或其他库添加到 Tomcat。

但根据引用建议使用JTA。

在这种情况下你有什么建议?

Quote from hib official docs:


Starting with version 3.0.1, Hibernate added the SessionFactory.getCurrentSession() method. Initially, this assumed usage of JTA transactions, where the JTA transaction defined both the scope and context of a current session. Given the maturity of the numerous stand-alone JTA TransactionManager implementations, most, if not all, applications should be using JTA transaction management, whether or not they are deployed into a J2EE container. Based on that, the JTA-based contextual sessions are all you need to use.

end of quotation

I use tomcat6 as a servlet container, and need to integrate Hibernate 3.2 into the project.

I found a document how to configure SessionFactory lookup through JNDI, though it does not work as expected.

Quote:

Hibernate works in any environment that uses JTA, in fact, we recommend to use JTA whenever possible as it is the standard Java transaction interface.

End of quote.

In hibernate config I indicate current_session_context_class = jta

and now I get an error "No TransactionManagerLookup specified".

The problem is that Tomcat does not support JTA, and to get it worked,
if I understand it correctly,
you need to add JOTM or other library to Tomcat.

But according to quote it is recommended to use JTA.

What can you recommend in this situation?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

等风来 2024-09-03 02:00:27

您的选择非常明确:

  1. 要么更改为支持 JTA 的 servlet 容器,
  2. 要么找到 JTA 之外的另一种事务机制,例如自己以编程方式控制事务。

Your choices are pretty clear:

  1. Either change to a servlet container that does support JTA
  2. Find another transaction mechanism other than JTA, such as programatically controlling transactions yourself.
情徒 2024-09-03 02:00:27

在这种情况下你有什么建议?

不使用 JTA 并使用 在视图中打开会话 模式来处理会话。

What can you recommend in this situation?

Do without JTA and use the Open Session In View pattern to handle the session.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文