为什么我的数据没有得到持久化?

发布于 2024-09-16 13:33:37 字数 1272 浏览 1 评论 0原文

我在我的应用程序中使用 JPA 和 Java Embedded DB。我尝试将一些数据写入数据库,当我尝试读回它时,我能够做到这一点。但是应用程序已关闭,当我再次打开它时,没有任何数据存在。

这是我的 persistence.xml 文件

    <?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.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_1_0.xsd">
  <persistence-unit name="myMoneyPU" transaction-type="RESOURCE_LOCAL">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <class>mymoney.Money</class>
    <properties>
      <property name="eclipselink.jdbc.password" value="adminadmin"/>
      <property name="eclipselink.jdbc.user" value="admin"/>
      <property name="eclipselink.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver"/>
      <property name="eclipselink.jdbc.url" value="jdbc:derby:pocketmoney;create=true"/>
      <property name="eclipselink.ddl-generation" value="create-tables"/>
    </properties>
  </persistence-unit>
</persistence>

我的数据库 URL 是否有任何问题。

jdbc:derby:pocketmoney

I am using JPA and Java Embedded DB in my application. I try to write some data to the database and when i try to read it back I am able to do it. But the application is closed and when I open it again none of the data exists.

Here is my persistence.xml file

    <?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.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_1_0.xsd">
  <persistence-unit name="myMoneyPU" transaction-type="RESOURCE_LOCAL">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <class>mymoney.Money</class>
    <properties>
      <property name="eclipselink.jdbc.password" value="adminadmin"/>
      <property name="eclipselink.jdbc.user" value="admin"/>
      <property name="eclipselink.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver"/>
      <property name="eclipselink.jdbc.url" value="jdbc:derby:pocketmoney;create=true"/>
      <property name="eclipselink.ddl-generation" value="create-tables"/>
    </properties>
  </persistence-unit>
</persistence>

Is there any problem in my database URL.

jdbc:derby:pocketmoney

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

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

发布评论

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

评论(1

秋心╮凉 2024-09-23 13:33:37

我的数据库 URL 是否有问题。

不,它是正确的,应该在当前工作目录中创建一个数据库。

调试问题的一些想法:

  • 使用绝对路径进行完全控制jdbc:derby:/path/to/pocketmoney;create=true
  • 检查数据是否已写入(即文件是否更改)。
  • 使用以下属性激活 EcliseLink 日志记录以查看到底发生了什么:

    <前><代码><属性>;
    ...
    <属性名称=“eclipselink.debug”值=“全部”/>
    <属性名称=“eclipselink.logging.level”值=“FINEST”/>
    <属性名称=“eclipselink.logging.level.sql”值=“FINEST”/>
    <属性名称=“eclipselink.logging.level.cache”值=“FINEST”/>

  • 仔细检查您是否正确提交了事务(您说您的代码正在执行操作,但您没有显示它,所以仍然有一个疑问)。

参考文献

Is there any problem in my database URL.

No, it is correct and should create a database in the current working directory.

Some ideas to debug your issue:

  • Use an absolute path for full control jdbc:derby:/path/to/pocketmoney;create=true.
  • Check that the data get written (i.e. that the files change).
  • Activate EcliseLink logging to see what is happening exactly using the following properties:

    <properties>
      ...
      <property name="eclipselink.debug" value="ALL"/>          
      <property name="eclipselink.logging.level" value="FINEST" />
      <property name="eclipselink.logging.level.sql" value="FINEST" />
      <property name="eclipselink.logging.level.cache" value="FINEST" />
    </properties>
    
  • Double check that you do commit transactions appropriately (you are saying your code is doing things but you're not showing it so there is still a doubt).

References

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