我的META-INF/persistence.xml怎么也找不到
我用J2SE,添加了JPA相关的lib,本来是个Hibernate的程序,我写好了META-INF/persistence.xml,类所在目录的结构如下:
+工作目录名
+lib
<省略这里的jar文件>
+build
+hello
HelloWorld.class
Message.class
+META-INF
persistence.xml
build目录是我的运行目录,相关Ant代码如下:
<target name="run" depends="package" description="Build and run HelloWorld">
<java fork="true" classname="hello.HelloWorld"
classpathref="project.classpath">
<classpath path="${build.dir}" />
</java>
</target>
project.classpath指向的是工作目录下的lib文件夹
${build.dir}指向build目录,
结果显示:
[java]
Exception in thread "main"
javax.persistence.PersistenceException: No Persistence provider for EntityManager named helloWorld
[java] at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)
[java] at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:33)
[java] at hello.HelloWorld.main(Unknown Source)
我知道是没有识别出来这个persistence.xml,该怎么解决呢?谢谢
perpersistence.xml内容如下:
<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="helloWorld">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>hello.Message</class>
<properties>
<property name="show_sql" value="true" />
<property name="format_sql"value="true" />
<property name="hibernate.connection.driver_class" value="org.hsqldb.jdbcDriver" />
<property name="hibernate.connection.url" value="jdbc:hsqldb:hsql://localhost" />
<property name="hibernate.connection.username" value="sa" />
<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect" />
<property name="hibernate.c3p0.min_size" value="5" />
<property name="hibernate.c3p0.max_size" value="20" />
<property name="hibernate.c3p0.timeout" value="300" />
<property name="hibernate.c3p0.max_statements" value="5" />
<property name="hibernate.c3p0.idle_test_period" value="3000" />
</properties>
</persistence-unit>
</persistence>
------解决方案--------------------
+META-INF
persistence.xml
放到src目录下面去
src
META-INF
persistence.xml