错误的原因是“在类路径中找不到META-INF / persistence.xml”?

时间:2011-04-20 18:55:50

标签: netbeans persistence.xml

包含所有necesaary toplinks lib在运行example.java时仍然出现以下错误

使用netbeans 6.8

在类路径中找不到META-INF / persistence.xml。

的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();

    }
}

目录结构

Root
|
|
|----src
|     |
|     |----conf
|          |
|          |-----Manifest.MF
|          |-----Persistence.xml   

1 个答案:

答案 0 :(得分:1)

persistence.xml 放在src / META-INF文件夹中。

此外,信件案件可能很重要。将 Persistence.xml 重命名为 persistence.xml