陷阱和实际用例:Toplink、Hibernate、Eclipse Link、Ibatis
我经常使用 Hibernate 作为我的 JPA 实现。 大多数情况下它工作得很好! 但我也看到了很多陷阱:
- 使用持久对象进行远程处理很困难,因为 Hibernate 用它自己的集合实现替换了 Java 集合。 因此每个客户端都必须有 Hibernate .jar 库。 您必须注意 LazyLoading 异常等。解决此问题的一种方法是使用 Web 服务。
- 脏检查是在没有任何锁的情况下对数据库进行的。
- “延迟 SQL”导致数据访问不符合 ACID。 (丢失数据...)
- 隐式更新>> 所以我们不知道对象是否被修改(提交导致更新)。
Toplink、Eclipse Link 和 Ibatis 是否也存在类似问题? 我什么时候应该使用它们? 他们有类似的表现吗? 是否有理由选择 Eclipse Link/Toplink... 而不是 Hibernate?
I worked a lot with Hibernate as my JPA implementation. In most cases it works fine! But I have also seen a lot of pitfalls:
- Remoting with persisted Objects is difficult, because Hibernate replaces the Java collections with its own collection implementation. So the every client must have the Hibernate .jar libraries. You have to take care on LazyLoading exceptions etc. One way to get around this problem is the use of webservices.
- Dirty checking is done against the Database without any lock.
- "Delayed SQL", causes that the data access isn't ACID compliant. (Lost data...)
- Implict Updates >> So we don't know if an object is modified or not (commit causes updates).
Are there similar issues with Toplink, Eclipse Link and Ibatis? When should I use them? Have they a similar performance? Are there reasons to choose Eclipse Link/Toplink... over Hibernate?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我可以分享我的大量 Hibernate 陷阱:
对于大多数 JPA 实现,我总是发现我必须依赖一些自定义注释或类似的东西来完成在JPA 规格
I can share my fair amount of Hibernate pitfalls:
As for most JPA implementations, I always found that I'd have to rely on some custom annotations or so to do stuff that it is not covered in the JPA spec.
在 O/R 映射器开发者领域(我居住的地方;)),一个普遍的事实是 Toplink 被认为是功能最完整和最好的 O/R 映射器。 它有其弱点,但其大量的功能使其难以被击败。 由于它现在是开源且免费的,我会尝试一下。
iBatis 并不是真正的 O/R 映射器,它更像是通过硬编码 SQL 进行的类填充/持久化。 因此,您必须完成繁重的工作并编写所有查询。 当您使用带有存储过程的数据库并且必须利用这些过程进行 DML/集检索时,iBatis 非常有用。
In O/R mapper developer land (where I live ;)) it's a common fact that Toplink is considered to be the most feature complete and best O/R mapper out there. It has its weaknesses, but its vast number of features makes it something that's hard to beat. As it's now open source and free, I'd give it a try.
iBatis is not really an O/R mapper, it is more of a class filler/persister through hard-coded SQL. So you've to do the heavy lifting and have to write all queries. iBatis is useful when you're using a database with stored procs and have to utilize these procs for DML/set retrieval.
无法评论其他实现,但对于 DataNucleus AccessPlatform ...
选择 DataNucleus 的原因记录在此处
HTH
--Andy DataNucleus
Can't comment on other implementations but for DataNucleus AccessPlatform ...
Reasons to choose DataNucleus are documented here
HTH
--Andy DataNucleus
关于 Ebean ORM http://www.avaje.org 和您的陷阱:
远程处理
您可以在查询中使用“vanilla”模式,然后 Ebean 将返回普通 bean 和集合 这仅在您使用“动态代理/动态子类”时有效,但如果您使用增强则无效(因为实体 bean 类明显得到增强)。
脏检查是在没有任何锁定的情况下对数据库进行的。
我相信你的意思是乐观并发检查? 如果是这样,那么根据定义,它是在没有显式数据库锁的情况下完成的。 如果您想要/需要数据库锁(选择更新等),您需要使用悲观锁定 - 所以我不遵循您的观点。
延迟SQL
Ebean没有会话,因此它没有会话flush()。 当您使用 JDBC 批处理时,Ebean 仍然可能会延迟 SQL,但这与使用 session flash() 获得的延迟不同。
隐式更新 这
是我们从前 Hibernate 和前 JPA 人员那里听到的常见抱怨。 Ebean 的架构没有会话/实体管理器。 相反,您需要显式 save() 一个 bean 或将其级联到相关的 bean。 所以是的,Ebean 没有隐式更新。
In regards to Ebean ORM http://www.avaje.org and your Pitfalls:
Remoting
You can use "vanilla" mode on a query and then Ebean will return plain beans and collections. This only works when you use "dynamic proxies/dynamic subclasses" but not if you use Enhancement (as the entity bean classes are obviously enhanced).
Dirty checking is done against the Database without any lock.
I believe you mean Optimistic Concurrency Checking? If so then by definition it is done without an explicit DB lock. You need to use Pessimistic Locking instead if you want/need a DB lock (select for update etc) - so I don't follow your point there.
Delayed SQL
Ebean doesn't have sessions and so it doesn't have session flush(). The SQL can still be delayed with Ebean when you use JDBC batching but it is not the same delay that you get with session flush().
Implicit Updates
A common complaint we hear from ex-Hibernate and ex-JPA folks. Ebean is architected without a session/entityManager. Instead you need to explicitly save() a bean or have that cascade to related beans. So yes, no implicit updates with Ebean.