2 a07151102108 A07151102108 于 2013.10.16 15:57 提问

初学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();
    //....
}

}

实在不知道如何下手,求助各位大神。

1个回答

Augu4
Augu4   2017.09.10 14:48

我跟你遇到的是一样的问题。如果你解决了可以告诉我一下…

Csdn user default icon
上传中...
上传图片
插入图片