This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes Newbie Question: What's the relationship between JPA and EJB? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Newbie Question: What Watch "Newbie Question: What New topic
Author

Newbie Question: What's the relationship between JPA and EJB?

Perry Terrance
Ranch Hand

Joined: Oct 02, 2009
Posts: 55
I know this is a newbie question but I want to get this history right.

From what I've been reading JPA/JPA2 were essentially offshoots of the EJB 3.0 specifications. However JPA-technologies and EJB technologies could be considered two mutually independent frameworks - though they could support each other quite well (being born from the same technology founders.) That why - most times - when using JPA-technologies, EJB 3.0 annotations are used to pair with it in its Entities.

So this is brings me to another question - does this mean that I do NOT have to use EJB 3.0 annotation (ex: @Entity) in JPA projects at all or any EJBs whatsoever? How will that work?
amit punekar
Ranch Hand

Joined: May 14, 2004
Posts: 511
Hi,
So this is brings me to another question - does this mean that I do NOT have to use EJB 3.0 annotation (ex: @Entity) in JPA projects at all or any EJBs whatsoever? How will that work?


Not correct..JPA needs to know which entities the PersistenceManager should manage and that is denoted by @Entity annotation.

Now regarding the relationship between JPA and EJB
Prior to EJB 3.0, we used to map database entities with Entity Beans. These entity beans needed the EJB Container to run them and they were not POJOs. Then came hibernate which addressed ORM (Object Relational Mapping) using POJO and without the need of Application server runtime. POJOs definitely has lot of advantages in terms of improving productivity and less number of classes to create, to name a few.
This lead to the thoght of deprecating earlier Entity beans model and aligning the EJB 3.0 entity beans with the POJO model as in Hibernate. If you have worked with hibernate then you can make out that the JPA specification is modelled on the Hibernate specifications. Gavin King who wrote hibernate was/is involved creating the JPA specifications.
The JPA entities can be worked with even outside the EJB Container that comes with Application server. Also now you do not need to write different home and remote interfaces to access these. You inject the PersistenceContext and start using the JPA entities. If you are using EJB 3.0 stateless/stateful/Messagedriven beans then using @PersistenceContext you can easily get hold of PersistenceContext and start using the JPA Entities.
The JPA entities can also be used in the Stand-alone mode in a simple Java application. I think there you need to get hold of PersistenceContext manually.
This is not all about EJB 3.0 and JPA but maybe you can find this useful while reading more about it.
Regds,
Amit
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Newbie Question: What's the relationship between JPA and EJB?
 
Similar Threads
Using JEE 5 for part 2 (old SCEA)
SCBCD 5.0 cleared with 100%
Hibernat versus EJB 3.0
Hibernate and EJB 3.0
EJB 3.0 and Hibernate