How does EJB and JPA relate?

LuckyLuke picture LuckyLuke · Jan 21, 2012 · Viewed 19.7k times · Source

I am reading the EJB 3 in Action book and I have the following question :
Is the POJO's you write and annotate with @Entity and so on also a EJB entity type?

I don't understand what JPA has to do with EJB. Isn't JPA a own specification now? The entities are also contained in a own persistence container. They talk about EJB 3 Java Persistence API etc. but I don't understand what entities has to do with EJB.

Answer

JB Nizet picture JB Nizet · Jan 21, 2012

JPA has been designed to replace EJB2 entity beans, and has started as a part of the EJB3 specification.

Since it makes sense to also use JPA outside of an EJB container, it has now its own specification, but it's still related to EJB3, since a compliant EJB3 container has to provide a JPA implementation, which integrates into the transaction handling of the container.