简体   繁体   中英

Provider in persistence.xml

I am new to java and trying to run sample programs using JPA. Code is getting compiled successfully, but when I run it, it is failing with below error.

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)

Can anyone tell me what exactly is provider in persistence.xml and how to decide what should be provided. Thanks in Advance.

Below is what I provided in persistence.xml (I got it from a sample training material)

<?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>

Do you have the toplink-essentials.jar in your classpath? Its the one that includes you oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider package...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM