阿帕奇德比 +杰帕

发布于 2024-12-29 02:30:58 字数 1043 浏览 4 评论 0原文

我嵌入了 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)

I have embedded derby database and i work with jpa. This is my 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>

What should i change or add to get this working. When I run my code now I get the following:

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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

晚风撩人 2025-01-05 02:30:58

您的 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)放入类路径中。

Your persistence.xml is not correct. Look at a sample below:

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

You also have to make sure that you put your JPA provider jar files (along with the derby-client jar) in the classpath.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文