EJB 3 或 Hibernate 3 [英] EJB 3 or Hibernate 3

查看:15
本文介绍了EJB 3 或 Hibernate 3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于将由完整的 Java EE 应用程序服务器提供服务的 Java EE Web 应用程序,例如GlassFish,哪个是最好的ORM 解决方案?EJB 3Hibernate 3为什么?

Regarding a Java EE Web application which is going to be served by a full Java EE Application server e.g. GlassFish, which is the best ORM Solution? EJB 3 or Hibernate 3 And why?

推荐答案

这两者完全不同.

EJB3 是一个组件模型,它本身与 ORM 没有直接关系.它确实有助于轻松管理事务并让您轻松访问 JPA 中的实体管理器,这是 Java EE 中的标准化 ORM 解决方案.

EJB3 is a component model and has itself nothing directly to do with ORM. It does help with easily managing transactions and giving you easy access to the entity manager from JPA, which is a standardized ORM solution in Java EE.

Hibernate (3) 确实是一个 ORM 解决方案,而且恰好实现了 JPA.

Hibernate (3) is indeed an ORM solution, and as it happens one that implements JPA.

所以一个更合乎逻辑的问题是,是使用标准化的 JPA 接口,还是直接使用 Hibernate 核心 API.那么接下来的问题可能是是单独使用 JPA,还是与 EJB 3 结合使用.

So a more logical question is whether to use the standardized JPA interfaces, or to use the Hibernate core API directly. Then a followup question could be whether to use JPA standalone, or in combination with EJB 3.

答案在一定程度上取决于您究竟需要什么,但通常将 JPA 与 EJB 3 结合使用是最简单的解决方案.独立使用 JPA 或 Hibernate 需要更多冗长的代码,并且您必须手动管理事务,这可能会很痛苦.

The answer depends a little on what you need exactly, but typically using JPA in combination with EJB 3 is the easiest solution. Using JPA or Hibernate standalone requires much more verbose code and you manually have to manage transactions, which can be a pain.

JPA 与 Hibernate 是另一场辩论.JPA 具有标准化接口的好处,因此更多的开发人员可能会熟悉它.另一方面,本机 Hibernate API 始终是 JPA 的超集,因此提供了更多功能.

JPA vs Hibernate is another debate. JPA has the benefit of having the standardized interfaces, so more developers will likely be familiar with it. On the other hand, the native Hibernate APIs are always a super set of those of JPA and thus offer more power.

通常,开发人员的代码主要基于 JPA,然后在有意义的地方使用一些 Hibernate 特定的注释或 API 调用.在 99.99% 的情况下,支持这种混合 API 使用.

Typically developers mainly base their code on JPA, and then use some Hibernate specific annotations or API calls where it makes sense. In 99.99% of the cases such mixed API usage is supported.

还要注意 Glassfish 与 EclipseLink 捆绑在一起,而不是与 Hibernate 捆绑在一起.EclipseLink 可与 Hibernate 相媲美,但比它早十多年.Hibernate 从 EclipseLink(当时称为 TopLink)中吸取了很多东西.

Do also note that Glassfish is bundled with EclipseLink, not with Hibernate. EclipseLink is comparable with Hibernate but predates it with more than a decade. Hibernate took a lot from EclipseLink (called TopLink back then).

另见我对类似问题的回答:通过 JPA 访问数据库表 Vs.Web 应用程序中的 EJB

See also this answer I gave to a similar question: Database table access via JPA Vs. EJB in a Web-Application

这篇关于EJB 3 或 Hibernate 3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆