我正在创建一个小型JPA项目。
但是当我运行主类时,我收到以下错误。
Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named ClientAccount
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:56)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:34)
at com.infinite.ClientAccountMain.main(ClientAccountMain.java:12)
持久性单元中的名称与实体管理器工厂中使用的名称相同
EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("ClientAccount");
<?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="ClientAccount">
<description>My Persistence Unit</description>
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>com.infinite.Order</class>
<class>com.infinite.Account</class>
<class>com.infinite.Client</class>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.jdbc.driver" value="com.microsoft.sqlserver.jdbc.SQLServerDriver" />
<property name="javax.persistence.jdbc.url" value="jdbc:sqlserver://localhost:3306;databaseName=testdatabase" />
<property name="javax.persistence.jdbc.user" value="test"/>
<property name="javax.persistence.jdbc.password" value="test"/>
</properties>
</persistence-unit>
答案 0 :(得分:0)
我认为Neil Stockton是对的,如果你搜索一下,你会找到答案。虽然我认为这必须与您的提供商信息有关。
尝试这样的东西。
对于OpenJPA
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
来源信息---&gt; http://openjpa.apache.org/builds/1.0.3/apache-openjpa- 1.0.3 /文档/手动/ jpa_overview_persistence.html
对于Hibernate
<provider>org.hibernate.ejb.HibernatePersistence</provider>
答案 1 :(得分:0)
导致此错误的原因有多种:
persistence.xml
文件中定义持久性单元。persistence.xml
文件(通常位于META-INF/persistence.xml
中)。检查它是否在正确的位置。