What is difference between JPA Project and EJB Project in Eclipse?

43,615

Solution 1

An EJB project is a project focused on the development of Enterprise Java Beans. Commonly, EJBs depend on Entitity Beans for persistence which are implemented using the JPA technology (think of JPA as a dependency of the EJB).

The reason that you have the option to create a JPA project independently of the EJB, is that some people might not want to use (or don't need to) EJBs but still, they need to use an ORM framework such as JPA. Such case could be for instance a web project (i.e. JSF) that would use JPA directly for persistence (no EJBs).

The takeaway point is that although EJB 3 used JPA for persistence, you don't have to necessarily use EJBs in your project (unless you need to do so) in order to benefit from an ORM framework such as JPA.

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. By doing so, eclipse will add the required libraries, create the necessary artifacts (persistence.xml) and enable the JPA related tooling on your IDE.

Solution 2

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.

The Java Persistence API originated as part of the work of the JSR 220 Expert Group. JPA 2.0 is the work of the JSR 317 Expert Group.

Persistence in this context covers three areas:

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

Enterprise JavaBeans (EJB) is a Java API developed by Sun Microsystems that defines a component architecture for multi-tier client/server systems.

EJB systems allow developers to focus on the actual business architecture of the model, rather than worry about endless amounts of programming and coding needed to connect all the working parts. This task is left to EJB server vendors. Developers just design (or purchase) the needed EJB components and arrange them on the server.

Because EJB systems are written in Java, they are platform independent. Being object oriented, they can be implemented into existed systems with little or no recompiling and configuring.

Solution 3

It depends on the version of Java EE you are using. In Java EE 6 we can have the EJBs in the WAR file itself. So one Dynamic web project would suffice.

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. You can have persistence related classes in EJB project itself and dont require a JPA project here.

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.

Share:
43,615
tmp
Author by

tmp

Updated on June 23, 2020

Comments

  • tmp
    tmp almost 4 years

    Which one is used when?

    When I want JSF + Stateless Bean + JPA Entity application I need EJB Project and Dynamic Web Project integrates in EAR Project?

  • Déjà vu
    Déjà vu about 12 years
    JPA stands for Java Persistence API, in case you wonder.