Application-Managed Persistence - No Persistence Provider for EntityManager
Is it possible to use Application-Managed Persistence in conjuction with
Container-Managed persistence? I am having issues gettting
application-managed persistence to work within a J2EE environment using
Sun Application Server 9.0 w/ Toplink persistence provider.
Here is the design that I have to use:
I have a lot of EJBs that use the same persistence unit that I have setup in
my persistence.xml (I will include it below) and they work fine. However, I
would like to use an entity class that will not be used within EJBs sessions
(instead within POJOs)... my understanding is that the POJO I would like to
use to manage this particular entity class cannot use the injected
container-managed persistence that I used in my EJBs. I checked out the
EJB Perstistence Specs (pg.116) to come up with retrieving the
EntityManager in this way for J2SE applications, however, I get an error
message.
EntityManagerFactory emf = javax.persistence.Persistence.createEntityManagerFactory("MyPU");
EntityManager em = emf.createEntityManager();
My Error: (from ExceptionObj.getMessage)
===========================================================
ERROR: No Persistence providerfor EntityManager named MyPU
persistence.xml
(the class my.package.MyClass is the one to be managed within a POJO)
===========================================================
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="MyPU" transaction-type="JTA">
<jta-data-source>jdbc/ptp</jta-data-source>
<class>my.package.EJBClass</class>
<class>my.package.MyClass</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties/>
</persistence-unit>
</persistence>
I know there is a "provider" tag for the persistence.xml file... I have tried:
<provider>oracle.toplink.essentials.PersistenceProvider</provider>
and
<provider>oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider</provider>
both of these are listed in toplink-essentials.jar, file:
META-INF/services/javax.persistence.spi.PersistenceProvider
Any help would be appreciated!
EJB 3.0 Persistence Specs
==========================================================
(file: ejb-3_0-fr-spec-persistence.pdf) at URL: http://jcp.org/aboutJava/communityprocess/final/jsr220/index.html

