gpt4 book ai didi

hibernate - EntityManager Hibernate 没有持久性提供程序

转载 作者:行者123 更新时间:2023-12-04 05:42:33 25 4
gpt4 key购买 nike

我有一个 No Persistence provider for EntityManager异常,并且无法弄清楚是什么导致了它。这是我的配置文件:

持久性.xml (存储在 src/META-INF 中)

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.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_2_0.xsd">
<persistence-unit name="HatifimJPA" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>entities.HatUser</class>
<properties>
<property name="hibernate.connection.driver_class" value="oracle.jdbc.driver.OracleDriver" />
<property name="hibernate.connection.username" value="Benny" />
<property name="hibernate.connection.password" value="oracle" />
<property name="hibernate.connection.url" value="jdbc:oracle:thin:@localhost:1521:xe" />
<property name="hibernate.dialect" value="org.hibernate.dialect.OracleDialect" />
</properties>
</persistence-unit>
</persistence>

异常(exception):

Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named HatifimJPA at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:69) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47) at testing.TestClass.main(TestClass.java:16)



唯一的区别是我正在尝试获取 EntityManagerpublic void main(...) { ... }但是,我不记得过去这样做有问题。

任何人都可以帮助指出我的问题可能存在的地方吗?

最佳答案

尝试将 persistence.xml 放到 src/main/resources/META-INF/
并将此代码放入 main 方法中:

EntityManagerFactory emf = Persistence.createEntityManagerFactory("HatifimJPA");
EntityManager em = emf.createEntityManager();

关于hibernate - EntityManager Hibernate 没有持久性提供程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11107208/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com