Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Where to put persistence.xml file

852559Apr 4 2011 — edited Apr 5 2011
Hi,
I have some problems in getting the application know about persistence unit. I have an enterprise application which uses a EJB that persists on a database.
Everything works fine if I put the persistence.xml in the EJB module but I would like to have the persistence unit in the EAR scope.
I've read I can:
define the unit by placing a JAR file in the lib directory of the EAR, the persistence unit will automatically be visible to all modules in the EAR

So, that's what I tried to do.

Here is the structure of my appplication:


eve:dist Eve$ jar -tf EnterpriseApplication3.ear
META-INF/
META-INF/MANIFEST.MF
DB2.jar
EJBModule1.jar
WebApplication1.war



and this is the structure of the DB2 jar file:


eve:dist Eve$ jar -tf DB2.jar
META-INF/
META-INF/MANIFEST.MF
META-INF/persistence.xml
eve:dist Eve$


I get this exception:
java.lang.IllegalStateException: Unable to retrieve EntityManagerFactory for unitName provaPU

I also tried to put the persistence.xml file directly in the archive (without the META-INF directory) but in this case the application won't event start and I'm getting this exception:
Caused by: java.lang.RuntimeException: Could not resolve a persistence unit corresponding to the persistence-context-ref-name [prova.NewSessionBean/entityManager] in the scope of the module called [EnterpriseApplication3#EJBModule1.jar]. Please verify your application.

Here is also the persistence.xml file itself:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.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_2_0.xsd">
<persistence-unit name="provaPU" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>jdbc/provaejb2</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="eclipselink.ddl-generation" value="create-tables"/>
</properties>
</persistence-unit>
</persistence>

Thanks for any help

Eve
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 3 2011
Added on Apr 4 2011
5 comments
962 views