【问题标题】:apache derby + jpa阿帕奇德比 + jpa
【发布时间】:2012-01-25 15:53:36
【问题描述】:

我已经嵌入了 derby 数据库并且我使用 jpa。这是我的 persistence.xml:

<?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="pers">

        <class>entities.Leverancier</class>
        <class>entities.Prijsproduct</class>
        <class>entities.Product</class>


    </persistence-unit>
</persistence>

我应该更改或添加什么才能使其正常工作。当我现在运行我的代码时,我得到以下信息:

Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named pers
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:33)
at test.Test.main(Test.java:19)

【问题讨论】:

  • 你的持久化提供者是什么?
  • 什么将用作 JPA 运行时提供程序(例如 Hibernate、EclipseLink、...)?您需要在persistence.xml 中提及。
  • 好吧,您实际上不需要在persistence.xml 中提及它只要您在CLASSPATH 中只放置一个JPA 实现。但问题是,使用的是哪一个

标签: java jpa persistence derby


【解决方案1】:

您的persistence.xml 不正确。请看下面的示例:

<persistence-unit name="MyAppPU" transaction-type="RESOURCE_LOCAL">    
    <!-- This is where you mention your JPA runtime provider e.g. it's EclipseLink here -->
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>    

    <class>mypkg.MyEntity</class>

    <properties>
      <property name="javax.persistence.jdbc.url" value="jdbc:derby://localhost:1527/my_schema"/>
      <property name="javax.persistence.jdbc.password" value="pass"/>
      <property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver"/>
      <property name="javax.persistence.jdbc.user" value="user"/>
    </properties>

</persistence-unit>

您还必须确保将 JPA 提供程序 jar 文件(连同 derby-client jar)放在类路径中。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-03-15
  • 2013-04-24
  • 2011-02-25
  • 1970-01-01
相关资源
最近更新 更多