我正在尝试使用 JPA 运行我的第一个应用程序,但问题似乎是没有找到 persistence.xml。
run:
[java] Driver loaded successfull.
[java] Got connection.
[java] Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named books
[java] at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:84)
[java] at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
[java] at com.primaryAnalysis.Main.main(Unknown Source)
[java] Java Result: 1
项目结构相同:
源代码 ├── java │ └── com │ ├── ejb │ │ └── 坚持 │ │ └── ejb3-persistence.jar │ ├── mysql │ │ └── jdbc │ │ └── 司机 │ │ └── mysql-connector-java-5.1.24-bin.jar │ └── 初级分析 │ ├── ... └── 资源 └── 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="books" transaction-type="JTA">
<provider>com.ejb.Persistence</provider>
<class>com.primaryAnalysis.Book</class>
<class>com.primaryAnalysis.Autor</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost/books" />
<property name="javax.persistence.jdbc.user" value="root" />
<property name="javax.persistence.jdbc.password" value="MyNewPass" />
<property name="toplink.ddl-generation" value="create-tables" />
</properties>
</persistence-unit>
</persistence>
我的build.xml中有taskdef 资源中资源目录的路径。
有任何想法吗?
谢谢。