问题描述
- 初学JPA,报错求助:No Persistence provider for EntityManager named
-
报错信息:
Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named jpatest
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:56)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:34)
at test.TestQuery.main(TestQuery.java:16)附:
<?xml version="1.0" encoding="UTF-8"?>
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="jpatest" transaction-type="RESOURCE_LOCAL"> <provider>org.hibernate.ejb.HibernatePersistence</provider> <properties> <!--配置数据库驱动 --> <property name="hibernate.connection.driver_class" value="oracle.jdbc.driver.OracleDriver" /> <!--配置数据库用户名 --> <property name="hibernate.connection.username" value="root" /> <!--配置数据库密码 --> <property name="hibernate.connection.password" value="root" /> <!--配置数据库url --> <property name="hibernate.connection.url" value="jdbc:oracle:thin:@192.168.10.10:1521:dbtest" /> </properties> </persistence-unit>
主方法:
public class TestQuery {public static void main(String[] args) { // TODO Auto-generated method stub EntityManagerFactory emf = Persistence.createEntityManagerFactory("jpatest"); EntityManager em = emf.createEntityManager(); //.... }
}
实在不知道如何下手,求助各位大神。
时间: 2024-11-17 19:35:00