繁体   English   中英

Eclipse中的JPA项目和EJB项目有什么区别?

[英]What is difference between JPA Project and EJB Project in Eclipse?

什么时候用哪一个?

当我想要 JSF + 无状态 Bean + JPA 实体应用程序时,我需要 EJB 项目和动态 Web 项目集成在 EAR 项目中?

一个EJB项目是一个专注于企业Java Beans开发的项目。 通常,EJB 依赖于实体 Bean 来实现持久性,这些实体 Bean 是使用 JPA 技术实现的(将 JPA 视为 EJB 的依赖项)。

您可以选择独立于 EJB 创建 JPA 项目的原因是,有些人可能不想使用(或不需要)EJB,但他们仍然需要使用 Z8B8A92C27C103F10168D764DD7969DD9CZ 框架,例如 ZA9074D1BD88935C51 例如,这种情况可能是 web 项目(即 JSF),该项目将直接使用 JPA 进行持久性(无 EJB)。

要点是,尽管 EJB 3 使用 JPA 进行持久性,但您不必在项目中使用 EJB(除非您需要这样做)才能从 ORM 框架(例如 ZA807CC44088935905016)中受益。

Now, to enable JPA on an EJB project in eclipse right-click on the project, go to "Project Facets" option and select the JPA facet. 通过这样做,eclipse 将添加所需的库,创建必要的工件 (persistence.xml) 并在 IDE 上启用 JPA 相关工具。

The Java Persistence API, sometimes referred to as JPA, is a Java programming language specification which describes the management of relational data in applications using Java Platform, Standard Edition and Java Platform, Enterprise Edition.

Java 持久性 API 起源于 JSR 220 专家组的工作。 JPA 2.0 是 JSR 317 专家组的工作。

在这方面的持久性包括三个方面:

the API itself, defined in the javax.persistence package
the Java Persistence Query Language (JPQL)
object/relational metadata

Enterprise JavaBeans (EJB) 是由 Sun Microsystems 开发的 Java API,它定义了多层客户端/服务器系统的组件架构。

EJB 系统允许开发人员专注于 model 的实际业务架构,而不用担心连接所有工作部件所需的无穷无尽的编程和编码。 此任务留给 EJB 服务器供应商。 开发人员只需设计(或购买)所需的 EJB 组件并将它们安排在服务器上。

因为 EJB 系统是用 Java 编写的,所以它们是平台无关的。 面向 object,它们可以在现有系统中实现,只需很少或不需要重新编译和配置。

这取决于您使用的 Java EE 的版本。 在 Java EE 6 中,我们可以在 WAR 文件本身中包含 EJB。 因此,一个 Dynamic web 项目就足够了。

If you are using Java EE 1.5 then you need to have a Dynamic Web project for JSF and for Stateless bean you need to have an EJB Project and also an enterprise project is need to bundle the WAR and JAR into an EAR. 您可以在 EJB 项目本身中拥有与持久性相关的类,并且此处不需要 JPA 项目。

Java EE provides the facility to make use of JPA independent of EJBs so if your application does not require EJBs but still want to make use of JPA then you can go for a JPA project.

暂无
暂无

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

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