• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

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

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

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

Thanks
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes. Both EJB and JPA are independant of each other.
 
Frankie Fuentes
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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!
 
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 1337
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 (https://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
 
Ranch Hand
Posts: 553
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic