简体   繁体   English

将EJB 2.x BMP实体bean与Hibernate 3.x混合使用

[英]Mixing EJB 2.x BMP entity beans with Hibernate 3.x

I have a large application that uses EJB 2.x entity beans (BMP). 我有一个使用EJB 2.x实体bean(BMP)的大型应用程序。 This is well-known to be a horrible persistence strategy (I can elaborate if necessary). 众所周知,这是一种可怕的持久性策略(如果有必要,我可以详细说明)。

I'd like to start migrating this application to use a much more expressive, transparent, and non-invasive persistence strategy, and given my company's previous experience with it, Hibernate 3.x is the obvious choice. 我想开始迁移这个应用程序以使用更具表现力,透明和非侵入性的持久性策略,并且考虑到我公司以前使用它的经验,Hibernate 3.x是显而易见的选择。

Migrating to Hibernate is going to take a while, as over 100 tables in the application use entity beans. 迁移到Hibernate需要一段时间,因为应用程序中有超过100个表使用实体bean。 So I'm looking at a phased approach where the two persistence strategies run in parallel, ideally on the same tables at the same time, if possible. 所以我正在研究一种分阶段的方法,其中两个持久性策略并行运行,如果可能的话,理想情况下同时在同一个表上运行。

My question is, what are the pitfalls (if any) of combining these two persistence strategies? 我的问题是,结合这两种持久性策略有哪些陷阱(如果有的话)? Will they get in each other's way? 他们会互相帮助吗?

As said jodonnel, you have to pay attention to caching, because if you use second-level caching in Hibernate and a table is modified outside of Hibernate, then Hibernate has no way to know that its cache entry is stale. 正如所说的jodonnel,你必须注意缓存,因为如果你在Hibernate中使用二级缓存并且在Hibernate之外修改了一个表,那么Hibernate无法知道它的缓存条目是陈旧的。

For the transactions, they should both use JTA provided by the container, so for that it should be safe. 对于事务,它们都应该使用容器提供的JTA,因此它应该是安全的。

I guess the thing to really be careful with is working with the Hibernate sessions. 我想要真正小心的是使用Hibernate会话。 Hibernate caches stuff, and that might get in the way. Hibernate缓存内容,这可能会妨碍。

Frankly I would recommend that if you adopt Hibernate, drop the Entity beans entirely. 坦率地说,我建议如果你采用Hibernate,完全删除实体bean。 Do your Hibernate work within session beans and let the session beans manage your transactions. 您的Hibernate是否在会话bean中工作,并让会话bean管理您的事务。

Or alternately use EJB 3, which is Hibernate standardized into the Java Persistence API. 或者使用EJB 3,它是Hibernate标准化为Java Persistence API。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM