aspose file tools*
The moose likes Object Relational Mapping and the fly likes Is it possible to use JPA 2.0 with EJB 3.0? (not EJB 3.1)? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Is it possible to use JPA 2.0 with EJB 3.0? (not EJB 3.1)?" Watch "Is it possible to use JPA 2.0 with EJB 3.0? (not EJB 3.1)?" New topic
Author

Is it possible to use JPA 2.0 with EJB 3.0? (not EJB 3.1)?

Frankie Fuentes
Ranch Hand

Joined: Mar 28, 2010
Posts: 41
Hi,

Is it possible to use JPA 2.0 with EJB 3.0? (not EJB 3.1)?

Thanks
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Yes. Both EJB and JPA are independant of each other.


[My Blog]
All roads lead to JavaRanch
Frankie Fuentes
Ranch Hand

Joined: Mar 28, 2010
Posts: 41
Christophe Verré wrote:Yes. Both EJB and JPA are independant of each other.


Thanks!

Just to make sure. Does this mean I can use JPA 2 to app servers that only supports J2EE 1.4? What about the persistence context? Would the container be smart enough to insert persistence context manager that implements JPA 2 even if your container is only implementing J2EE 1.4? I mean, how is that possible? Will including a JPA 2 library override the persistence context that the container will attempt to inject in my ejbs?

Thanks again!
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
Does this mean I can use JPA 2 to app servers that only supports J2EE 1.4?

Maybe, but not in the way you envision it. First of all, J2EE 1.4 does not support EJB 3 at all - it supports EJB 2. That means it can't use any version of JPA for container-managed persistence (JPA 1 was part of JEE 5, which introduced EJB 3).

That said, *if* the JVM supports Java 6, then your code could use JPA 2, but not for EJBs because the container doesn't know about JPA.
Frankie Fuentes
Ranch Hand

Joined: Mar 28, 2010
Posts: 41
Lester Burnham wrote:
Does this mean I can use JPA 2 to app servers that only supports J2EE 1.4?

Maybe, but not in the way you envision it. First of all, J2EE 1.4 does not support EJB 3 at all - it supports EJB 2. That means it can't use any version of JPA for container-managed persistence (JPA 1 was part of JEE 5, which introduced EJB 3).

That said, *if* the JVM supports Java 6, then your code could use JPA 2, but not for EJBs because the container doesn't know about JPA.


Oops sorry, my bad. I meant JavaEE 5. Is it possible to use JPA 2 with JavaEE 5 app servers? If it is, how does the container know what version of persistence context to create during dependency injection?

Thanks
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
Is it possible to use JPA 2 with JavaEE 5 app servers? If it is, how does the container know what version of persistence context to create during dependency injection?

You can use a JPA 2 *implementation* (like Hibernate 3.5 or OpenJPA 2) with JEE 5 -because JPA 2 is a superset of JPA 1- but since the app server knows nothing about JPA 2, it will only make use of JPA 1 features.
Frankie Fuentes
Ranch Hand

Joined: Mar 28, 2010
Posts: 41
Lester Burnham wrote:
Is it possible to use JPA 2 with JavaEE 5 app servers? If it is, how does the container know what version of persistence context to create during dependency injection?

You can use a JPA 2 *implementation* (like Hibernate 3.5 or OpenJPA 2) with JEE 5 -because JPA 2 is a superset of JPA 1- but since the app server knows nothing about JPA 2, it will only make use of JPA 1 features.


That surely saves me some time. I had been hoping in vain. I was actually trying to solve a composite key mapping problem (http://www.coderanch.com/t/504782/ORM/java/Composite-Key-consisting-Entity-Property) which I think was resolved in JPA 2. Got to think of another solution I guess.

Thanks anyways
James Sutherland
Ranch Hand

Joined: Oct 01, 2007
Posts: 553
Well, the real answer is more complicated than this.

Basically it depends on your server and JPA provider, and usage.

JPA 2.0 is backward compatible with JPA 1.0, so you can probably just replace your server's jar and have most things work.

Configuration of JPA 2.0 done through xml will probably just work, as well as annotations, as the new annotations will just be processed by the JPA provider.

EntityManager API for a managed EntityManager will most likely not work, but this depends on the server. For example WebLogic has a dynamic proxy for the EntityManager, and will pick up the new API if you replace the jar.

EclipseLink ships the new JPA 2.0 classes in its jar, so that most JPA 2.0 functionality will work in a JEE 5 app server.

Best way is just to try it and see.

TopLink : EclipseLink : Book:Java Persistence : Blog:Java Persistence Performance
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is it possible to use JPA 2.0 with EJB 3.0? (not EJB 3.1)?