0

Included all necesaary toplinks lib still getting following error on running example.java

using netbeans 6.8

No META-INF/persistence.xml was found in classpath.

Persistence.xml

<?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="MatdaanPU" transaction-type="JTA">
    <provider>oracle.toplink.essentials.PersistenceProvider</provider>
    <jta-data-source>matdaan</jta-data-source>
    <class>EntityBeans.Trial</class>
    <exclude-unlisted-classes>true</exclude-unlisted-classes>
    <properties>
      <property name="toplink.ddl-generation" value="create-tables"/>
    </properties>
  </persistence-unit>
</persistence>

Example.java

import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
public class Example {
    public Example() {

        EntityManagerFactory emf=Persistence.createEntityManagerFactory("MatdaanPU");
        EntityManager em=emf.createEntityManager();
       List results = em.createNamedQuery("Trial.findById")
    .setParameter("id", "1")
    .getResultList();
       System.out.println("HI");
        System.out.println(results.get(1));
    }

    public static void main(String args[]){
        Example e=new Example();

    }
}

Directory structure

Root
|
|
|----src
|     |
|     |----conf
|          |
|          |-----Manifest.MF
|          |-----Persistence.xml   
Matt Handy
  • 29,855
  • 2
  • 89
  • 112
Mayank
  • 1
  • 1

1 Answers1

1

Put your persistence.xml in src/META-INF folder.

Furthermore letter case could matter. Rename Persistence.xml to persistence.xml

Matt Handy
  • 29,855
  • 2
  • 89
  • 112