如何使用 Derby 和 Eclipselink 在 glassfish v3 上为 ORM 配置 persistence.xml

发布于 2025-01-05 18:27:43 字数 649 浏览 0 评论 0 原文

我正在使用 Eclipse 的内部 glassfish 3.1 插件以及我安装的 derby 数据库(它显示在 Eclipse 的数据库开发人员视图中的数据源资源管理器上),并且我正在摸索着获取ORM 的工作使我可以开发一个应用程序,使用 Eclipselink 来实现 JPA 并使用 EJB 保存数据。

我知道我需要配置 persistence.xml 文件,但我不知道其中需要什么,各个字段名称的含义是什么。我觉得 persistence.xml 的目的是告诉 Glassfish 在哪里可以找到存储所有内容的数据库,以及使用哪个 JPA 实现来进行存储。

我有很多问题。

  1. 对于代表数据库中对象的每个类,我是否必须有一个持久性条目?因此,如果我有一个 Book 类和一个 Library 类,我是否需要 persistence.xml 中的两个条目,或者我可以只做一个为它们提供服务的案例吗?

  2. 在哪里可以找到有关如何配置 persistence.xml 文件的更多信息。 配置它的信息,但没有任何内容解释各个位以及如何从高级别配置它们。

  3. 一旦我正确设置了 persistence.xml 文件,我还需要做什么来确保 ORM 实现正确地为我的 @annotated 类提供服务?我需要在 Glassfish 中配置什么吗?

I'm using the internal glassfish 3.1 plugin for Eclipse, along with a derby database I installed (it shows up on the datasource explorer in the Database Developer view in Eclipse), and I'm fumbling at the "last" step of getting the ORM working so that I can develop an app that persists data with EJBs using Eclipselink for the JPA implementation.

I know I need to configure the persistence.xml file, but I'm at a loss for what needs to be in it, what the individual field names mean. I feel like the purpose of the persistence.xml is to tell Glassfish where to find the database to store everything in, and which JPA implementation to use to do that storing.

I have a bunch of questions.

  1. Do I have to have a persistence entry for each class that represents an object in the database? So if I had a Book class and a Library class, would I need two enteries in persistence.xml or could I just do one case that services them both?

  2. Where can I find more information about how to configure the persistence.xml file IN GENERAL. I have found tons of very specific tutorials with information on how to configure it in X, Y, or Z setting, but nothing that explains the individual bits, and how you'd configure them from a high level.

  3. Once I've setup my persistence.xml file correctly, what else do I need to do to ensure that my @annotated classes are going to be serviced by the ORM implementation correctly? Is there something I need to configure in Glassfish?

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

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

发布评论

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

评论(1

心房的律动 2025-01-12 18:27:43

我不是专家,但是...

1) 是的,根据我的经验,每个课程都需要一个条目。可能会有例外,但我对它们不熟悉。

2) [http://wiki.eclipse.org/EclipseLink/] 是一个很好的起点。
[http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Basic_JPA_Development/Configuration/JPA/persistence.xml] 有一些您可能已经知道的详细信息。我自己很难找到完美的资源。我倾向于发现到处都是支离破碎的信息。

3)一般来说,我的大部分 persistence.xml 文件都是由 eclipselink 自动生成的。
从 glassfish 管理控制台创建连接池和 JDBC 资源后
我必须将

jdbc/your_name

添加到 persistence.xml。[1]

<property name="eclipselink.ddl-generation" value="create-tables"/>
<property name="eclipselink.ddl-generation.output-mode" value="database"/>

我添加了这些属性,以便我的身份列可以使用 JPA 自动递增。

尝试这两个教程以更好地了解其工作原理:

[1] http://programming.manessinger.com/tutorials/an-eclipse-glassfish-java-ee-6-tutorial/#heading_toc_j_24

http://itsolutionsforall.com/index.php

[*抱歉,我目前无法发布超过 2 个链接]

I'm not an expert but...

1) Yes, in my experience you need an entry for each class. There could be exceptions to this but I am unfamiliar with them.

2) [http://wiki.eclipse.org/EclipseLink/] is a good place to start.
[http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Basic_JPA_Development/Configuration/JPA/persistence.xml] has some details that you may already know. I've have trouble finding a perfect resource myself. I've tended to find information fragmented all over the place.

3) In general most of my persistence.xml file has been generated automatically by eclipselink.
After I creating a connection pool and JDBC resource from the glassfish Administration Console
I had to add my

<jta-data-source>jdbc/your_name</jta-data-source>

to persistence.xml.[1]

<property name="eclipselink.ddl-generation" value="create-tables"/>
<property name="eclipselink.ddl-generation.output-mode" value="database"/>

I added these properties so my identity columns would auto-increment using JPA.

Try these two tutorials to get a better understanding of how it works:

[1] http://programming.manessinger.com/tutorials/an-eclipse-glassfish-java-ee-6-tutorial/#heading_toc_j_24

http://itsolutionsforall.com/index.php

[*apologies I can't post more than 2 links at the moment]

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