File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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 Murach's Java Servlets and JSP this week in the Servlets 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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30050
    
149

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
 
 
subject: JPA2 and Glassfish: persistence unit not found
 
Similar Threads
Could not resolve a persistence unit corresponding to the persistence-context-ref-name
Problem in generating the Primary Key using a Sequence
Error when trying to use an extended persistence context in EJB 3
JPA: Can't find Persistence Provider
Trying to use entities in a library in another EJB