• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

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

 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 544
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 didn't do it. You can't prove it. Nobody saw me. The sheep are lying! This tiny ad is my witness!
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic