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

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

问题描述

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

解决方案

这两个是完全不同的。

EJB3 是一个组件模型,与ORM没有直接关系。它有助于轻松管理事务,并让您可以轻松地从JPA获得实体管理器,这是Java EE中的标准化ORM解决方案。 Hibernate (3)确实是一个ORM解决方案,并且正好是一个实现JPA的解决方案。



所以更合乎逻辑的问题是是否使用标准化的JPA接口,或直接使用Hibernate核心API。然后,后续问题可能是使用JPA独立还是与EJB 3结合使用。



答案取决于您需要的确切内容,但通常使用JPA in与EJB 3结合是最简单的解决方案。使用JPA或Hibernate standalone需要更多冗长的代码,而且您必须手动管理事务,这可能很痛苦。



JPA vs Hibernate是另一场辩论。 JPA具有标准化接口的好处,因此更多的开发人员可能会熟悉它。另一方面,原生Hibernate API总是超级JPA的集合,因此提供更多的功能。

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



还要注意Glassfish与 EclipseLink 捆绑在一起,而不是Hibernate。 EclipseLink可以与Hibernate相媲美,但它早于十年。 Hibernate在EclipseLink方面花了很多功夫(当时称为TopLink)。



另请参阅我对类似问题的回答:通过JPA比较数据库表访问EJB在Web应用程序中


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?

解决方案

Those two are completely different.

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) is indeed an ORM solution, and as it happens one that implements JPA.

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.

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 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.

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.

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).

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天全站免登陆