[java] Why should we use EJB?



Answers

EJB beans are specifically designed to implement the business logic of your application. As such they provide services that are often needed when implementing such logic, such as transactions, injecting of the entity manager (used for JPA, the Java Persistence API) and pooling of beans.

See this for a more elaborate answer and even more references: What use are EJBs

In the most basic wording possible; "EJB beans make it a lot easier to work with a database via JPA".

Using JPA outside an EJB requires a lot of verbose and error prone code for obtaining an entity manager, starting a transaction and committing it or rolling it back.

There are a ton of other reasons to use EJB, but from experience I think that is the number one reason.

Question

What is EJB, and why we should use it? Please explain in simple language. Thank you.







Links



Tags

java java   ejb-3.0