尝试使用jpa连接到数据库时出错

时间:2015-12-16 22:45:38

标签: java jpa

请你帮我解决这个错误。我在eclipse中运行这段代码并使用jpa 2.0及以下版本是我的persistence.xml和错误。任何帮助表示赞赏。我已经坚持了一天。

Exception in thread "main" java.lang.NoClassDefFoundError: org/hibernate/proxy/EntityNotFoundDelegate
    at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:54)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:79)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
    at com.test.Main.main(Main.java:12)
Caused by: java.lang.ClassNotFoundException: org.hibernate.proxy.EntityNotFoundDelegate
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 4 more

My Persistence.xml

<persistence 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"

  version="2.1">

  <persistence-unit name="jpa-example" >
    <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
    <class>com.test.User</class>
    <properties>
      <!-- Configuring JDBC properties -->
      <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306//test_pk" />
      <property name="javax.persistence.jdbc.user" value="root" />
      <property name="javax.persistence.jdbc.password" value="root" />
      <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />

         </properties>
  </persistence-unit>
</persistence>

0 个答案:

没有答案