Struts 应用中的 EJB 和 Hibernate

发布于 2024-10-01 01:06:26 字数 780 浏览 0 评论 0原文

我有一个具有 struts 1.1 和 EJB 2 组合的应用程序,但现在我们使用 hibernate 3.2 向其中引入一个新部分。 hibernate DAO 与使用纯 JDBC 的 EJB 2 会话 bean DAO 并行运行。我担心这种情况下的 jdbc 连接管理。由于 EJB 2.0 具有容器管理的连接和事务。但在休眠的情况下,我们开始并提交休眠事务,可以安全地假设该架构不会出现任何问题吗?

需要一些分析帮助。

PM


我正在​​考虑同样的问题,如果 hibernate 模块可能访问 JDBC DAO 使用的现有表(其事务由会话 Bean 管理)。但这是我的方法:

  1. 我将有一个调用 EJB 会话 bean 的委托,并且由于该 bean 将负责管理事务,因此我将创建我的 hibernate DAO 并从该会话 bean 调用它们,我认为这会没有任何问题。

  2. 此应用程序的 hibernate 会话工厂将使用 hibernate 插件实例化一次,该插件将成为 struts 配置 xml 的一部分,并将保存为 servlet 上下文的一部分,然后操作类将从 EJB 传递此 sessionfactory 实例会话 bean 委托给 hibernate DAO。

  3. 我想这将是一个干净的方法,因为事务将由部署到 websphere 上的 EJB 会话 bean 进行管理。由于 JDBC 连接池管理是在 websphere 上配置并使用数据源访问的,因此 hibernate 不必担心这一点。

如果我的假设走在正确的道路上,请帮助我?

I have an application that has a struts 1.1 and EJB 2 combination, but now we are introducing a new piece into it with hibernate 3.2. The hibernate DAO's run in parallel with the EJB 2 session bean DAO's with pure JDBC. I am concerned about the jdbc connections management in this case. Since EJB 2.0 has container managed connections and transactions. But in the case of hibernate we begin and commit a hibernate transaction, Will it be safe to assume there will not be any issues with this architecture.

Need some analysis help.

PM


I was contemplating on the same issue, if hibernate module which might access existing tables being used by JDBC DAO's whose transaction is managed by Session Beans. But here is my approach:

  1. I will have a delegate that invokes the EJB session bean, and since this bean will be responsible to manage transactions, I will create my hibernate DAO's and invoke them from this session bean, which I assume will not have any issues.

  2. The hibernate session factory for this application will be instantiated once using the hibernate plugin that will be part of the struts config xml and will be saved as part of the servlet context and then the action class will pass this sessionfactory instance from the EJB session bean delegate to the hibernate DAO.

  3. I guess this will be a clean approach, since the transaction will be managed by the EJB Session bean which are deployed onto the websphere. The JDBC connection pools management since is configured on the websphere and being accessed using the datasources, hibernate does not have to worry about this.

Please help me if I am on the right path with my assumptions ?

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

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

发布评论

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

评论(3

荆棘i 2024-10-08 01:06:26

事务划分了工作的逻辑单元,因此本质上是隔离的。但我想知道为什么你需要两者的结合。如果您已经在使用 EJB2 + JDBC 为什么不坚持这样做呢?

Transactions demarcate logical unit of work and hence are inherently isolated. But I am wondering why you need a combination of both. If you are already using EJB2 + JDBC why not stick to this?

嗫嚅 2024-10-08 01:06:26

Hibernate 可以毫无问题地与 CMT(或 BMT)会话 bean 一起使用,与 JDBC 代码共享连接池并参与同一事务。

请参阅整个部分11.2。数据库事务划分,特别是11.2.2。使用 JTA

尚不清楚的是 Hibernate 模块是否会与通过 JDBC 管理的实体“隔离”。如果您将通过两个 API 访问相同的表,则必须采取一些预防措施:

  • 不要期望在 Hibernate 实体图中混合 JDBC 实体(但反过来也是可能的)。
  • 通过 JDBC 更新行时尊重并模仿 Hibernate 乐观并发策略,
  • 绕过 Hibernate 的 API 不会触发任何缓存更新(如果您使用二级缓存),在这种情况下您必须自己触发它。

Hibernate can be used without any problem with CMT (or BMT) session beans, share a connection pool with JDBC code and participate in the same transaction.

See the whole section 11.2. Database transaction demarcation and in particular 11.2.2. Using JTA.

What is not clear is if the Hibernate module will be "isolated" from the entities managed via JDBC. If you'll access the same tables via both APIs, you'll have to take some precautions:

  • don't expect to mix JDBC entities in a graph of Hibernate entities (the inverse is possible though).
  • respect and mimic Hibernate optimistic concurrency strategy when updating rows via JDBC
  • bypassing Hibernate's API won't trigger any cache update (if you're using the 2nd level cache) in which case you'd have to trigger it yourself.
柒夜笙歌凉 2024-10-08 01:06:26

这是可能的解决方案之一:

公共 JNDI 数据源,它将在 EJB 和 Hibernate 中使用。

Here is one of the possible solutions

A common JNDI Datasource, which will be used both in EJB's and Hibernate.

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