aspose file tools*
The moose likes Object Relational Mapping and the fly likes JPA2 and Glassfish: persistence unit not found Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "JPA2 and Glassfish: persistence unit not found" Watch "JPA2 and Glassfish: persistence unit not found" New topic
Author

JPA2 and Glassfish: persistence unit not found

Antonio Fornie
Ranch Hand

Joined: Aug 07, 2008
Posts: 117
Hello!

I'm trying to make a test project with JEE6 in Glassfish and I'm getting an error related to my persistence unit:

That's my persistence.xml
-------------------------------
<?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="VuelosWebPersistenceUnit" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<properties>
<property name="eclipselink.target-database" value="DERBY" />
<property name="eclipselink.ddl-generation" value="create-tables" />
<property name="eclipselink.logging.level" value="FINE" />
<property name="eclipselink.jdbc.url" value="jdbc:derby://localhost:1527/dbname" />
<property name="eclipselink.jdbc.user" value="user" />
<property name="eclipselink.jdbc.password" value="pwd />
</properties>
</persistence-unit>

</persistence>
-------------------------------

My SLSB has this conflicting code:

...
@PersistenceContext
EntityManager em;
...

I tried too with this code
...
@PersistenceContext(name="VuelosWebPersistenceUnit", unitName="VuelosWebPersistenceUnit")
EntityManager em;
...
with the same result.

The error is this one:
Unable to retrieve EntityManagerFactory for unitName VuelosWebPersistenceUnit

And my persistence.xml file is in this path ${warfile}/META-INF/persistence.xml

Any ideas what's my problem or how to solve it?

Thank you very much!

antonio>


I feel there must be far better ways to do what I do... that makes learning even funnier
James Sutherland
Ranch Hand

Joined: Oct 01, 2007
Posts: 553
Not certain, but if you have an EJB shouldn't you have an ear not a war?

I believe your persistent xml and persistent classes should all be in a jar inside your ear file.

TopLink : EclipseLink : Book:Java Persistence : Blog:Java Persistence Performance
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30764
    
156

James Sutherland wrote:Not certain, but if you have an EJB shouldn't you have an ear not a war?

You definitely have an EAR. It can contain a WAR though.

James Sutherland wrote:I believe your persistent xml and persistent classes should all be in a jar inside your ear file.

In any case, this is the important point. That the persistence.xml goes in the jar.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Antonio Fornie
Ranch Hand

Joined: Aug 07, 2008
Posts: 117
Not with JEE6, in fact my EJB works perfectly when I don't use JPA. But it's the JAP persistence.xml file that must have an error... the problem is it doesn't show any information about it, not any log.

And I don't even know for sure if my properties prefix is the correct one for the default Glassfish JPA implementation.

Thank you very much for your replies! Any other idea?

antonio
 
wood burning stoves
 
subject: JPA2 and Glassfish: persistence unit not found