persistence.xml

时间:2015-07-23 00:09:11

标签: java jpa

我是java新手并尝试使用JPA运行示例程序。代码正在成功编译,但是当我运行它时,它失败并出现以下错误。

Exception in thread "main" javax.persistence.PersistenceException: No     Persistence provider for EntityManager named FirstProject:  The following providers:
oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider
oracle.toplink.essentials.PersistenceProvider
Returned null to createEntityManagerFactory.

    at      javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:154)
    at  javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:83)
    at com.infybank.services.AccountDS.main(AccountDS.java:35)

任何人都可以告诉我persistence.xml中究竟是什么提供者以及如何决定应该提供什么。在此先感谢。

以下是我在persistence.xml中提供的内容(我从示例培训材料中获取)

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence"     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence     http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
    <persistence-unit name="FirstProject">
    <provider>oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider</provider>
<class>com.infybank.entities.Account</class>

<properties>
<property name="toplink.jdbc.url" value="jdbc:oracle:thin:@localhost:1521:testdb"/>
<property name="toplink.jdbc.user" value="user"/>
<property name="toplink.jdbc.driver" value="oracle.jdbc.driver.OracleDriver"/>
<property name="toplink.jdbc.password" value="password"/>
<property name="toplink.ddl-generation" value="create-tables"/>
<property name="toplink.jdbc.read-connections.max" value="1"/>
<property name="toplink.jdbc.read-connections.min" value="1"/>
<property name="toplink.jdbc.write-connections.max" value="1"/>
<property name="toplink.jdbc.write-connections.min" value="1"/>
<property name="toplink.logging.level" value="SEVERE" />
</properties>
</persistence-unit>
</persistence>

1 个答案:

答案 0 :(得分:0)

你的classpath中有toplink-essentials.jar吗?它包括你oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider包...