What is the difference between a JPA project and an EJB project in Eclipse?

Which one is used when?

When I need a JSF + Stateless Bean + JPA Entity application, do I need an EJB Project and Dynamic Web Project in an EAR project?

+6
source share
3 answers

An EJB project is a project focused on developing Enterprise Java Beans. Typically, EJBs depend on Entityity Beans for persistence, which are implemented using JPA technology (think of JPA as EJB dependencies).

The reason you have the opportunity to create a JPA project independently of an EJB is because some people may not want to use (or do not need) an EJB, but still they need to use an ORM infrastructure such as a JPA. Such a case could be, for example, a web project (i.e. JSF) that would use JPA directly for saving (without EJB).

The ransom point is that although EJB 3 used JPA to save, you do not have to use EJB in your project (if you don't need it) to benefit from an ORM framework such as JPA.

Now, to include JPA in an EJB project in eclipse, right-click the project, go to the "Project Boundaries" option and select the JPA face. By doing so, eclipse will add the necessary libraries, create the necessary artifacts (persistence.xml), and enable JPA-related tools in your IDE.

+14
source

The Java Persistence API, sometimes called JPA, is a Java programming language specification that describes the management of relational data in applications using the Java platform, the standard version, and the Java platform, Enterprise Edition.

The Java Persistence API was created 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 the component architecture for tiered client-server systems.

EJB systems allow developers to focus on the real business architecture of the model, rather than worry about the endless amounts of programming and coding needed to connect all the working parts. This challenge remains for EJB server providers. Developers simply design (or purchase) the necessary EJB components and place them on the server.

Because EJB systems are written in Java, they are platform independent. Being object oriented, they can be embedded in existing systems with little or no recompilation and customization.

+5
source

It depends on the version of Java EE you are using. In Java EE 6, we can have EJBs in the WAR file itself. Thus, one dynamic web project will be sufficient.

If you use Java EE 1.5, you need to have a Dynamic Web project for JSF, and for Stateless bean you need an EJB project, and the enterprise project must combine WAR and JAR in EAR, you can have persistence classes in the EJB project itself and do not require a JPA project here.

Java EE provides the ability to use JPA independently of the EJB, so if your application does not require EJB but still wants to use JPA, you can go for a JPA project.

+1
source

Source: https://habr.com/ru/post/887344/


All Articles