如何配置&打包一个简单的 Java 应用程序以使用 JPA
我正在尝试学习 JPA,我想创建一个简单的 Java 命令行应用程序,它将使用 JPA 来查询和更新数据库表。我列出了执行此操作所需的简单代码。但我不知道如何配置目录结构、将persistence.xml文件放在哪里、打包等等。这只是一个快速而肮脏的学习练习,所以我想让它尽可能简单。有人可以阐明执行此操作的步骤吗?
我使用的是Weblogic 10.3。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
persistence.xml 位于与持久性类处于同一级别的
META-INF
目录中。 这是一个示例一些有效和无效的配置。在我编写的非 Java EE 应用程序中,我在 WEB-INF/classes/META-INF/ 中使用 persistence.xml 构建 JAR,因为我的 JPA 类位于 WEB- INF/类/。persistence.xml goes in the
META-INF
directory that is at the same level as your persistence classes. Here's an example of some valid and invalid configurations. In the non-Java EE apps I've written, I build the JAR with persistence.xml inWEB-INF/classes/META-INF/
, because my JPA classes are inWEB-INF/classes/
.不确定是否了解 WebLogic 与 Java 命令行应用程序有什么关系:)
不管怎样,所有您正在寻找的详细信息都可以在 Java EE 5 教程,我在下面引用:
Not sure to understand what WebLogic has to do with a Java command line app :)
Anyway, all the details you are looking for are available in the Persistence Units section of The Java EE 5 Tutorial that I'm quoting below: