2

I have a simple JPA/Hibernate Project in Eclipse (Helios) IDE. I have placed the persistence.xml in Project>resources dir. And in Eclipse i have added this directory(Project\resources) to the classpath.

Yet when i run my appln frm within Eclipse IDE, i see this error: javax.persistence.PersistenceException: No Persistence provider for EntityManager named XX

In Eclipse, i've following Libraries: hibernate3.jar hibernate-jpa-2.0-api-1.0.0.Final.jar hibernate-entitymanager-3.6.0.Final.jar and rest are supporting jars...

My persistence.xml is:

<?xml version="1.0" encoding="UTF-8"?>
<persistence 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"
    version="1.0">

    <persistence-unit name="XX" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <!-- the JNDI data source -->
        <non-jta-data-source>java:comp/env/jdbc/tutorialDS</non-jta-data-source>
        <properties>
            ...
        </properties>
    </persistence-unit>
</persistence>

What is causing this error in Eclipse IDE? Thanks

Jasper
  • 8,440
  • 31
  • 92
  • 133

3 Answers3

3

So the solution:

In Eclipse > Properties > Java Build Path
Source Tab - there was: Excluded: META-INF/
This was causing the META-INF dir to be completely ignored, and persistence.xml was not found.
On deleting that Excluded:META-INF/ line, persistence.xml is now found successfully.

How did- Excluded: META-INF/ end up in Java Build Path > 'Source' tab?
Earlier under the 'Libraries' Tab, i had done: 'Add Class Folder' : src/META-INF
This automatically resulted in Excluded: META-INF/ under 'Source' tab.

Hope this helps someone.

Jasper
  • 8,440
  • 31
  • 92
  • 133
1

The persistence.xml must be placed inside META-INF directory.

Edit: don't forget include the library of the driver for your database.

Guillermo
  • 1,523
  • 9
  • 19
0

Have you tried to keep this persistence.xml file into class path META-INF folder.

{CLASS_PATH}/META-INF/persistence.xml 
Shamim Ahmmed
  • 8,265
  • 6
  • 25
  • 36
  • Yes... i hv tried that, thats where its original location was - it does not help. – Jasper Aug 14 '13 at 16:47
  • @Jasper, where you have defined your , java:comp/env/jdbc/tutorialDS? Could you please make sure your data source is accessible – Shamim Ahmmed Aug 14 '13 at 17:12
  • I have deleted that line, and it makes no diff. Its as if persistence.xml is just not found. – Jasper Aug 14 '13 at 17:23
  • Shammim> i just figured out the problem, pls see my answer. It was a mistake on my part. Thanks for your insights though. – Jasper Aug 14 '13 at 17:45