问题描述
我正在尝试学习JPA,我想创建一个简单的Java命令行应用程序,该应用程序将使用JPA查询和更新数据库表.我映射了执行此操作所需的简单代码.但是我不知道如何配置目录结构,在哪里放置persistence.xml文件,打包等等.这只是一个快速而肮脏的学习练习,所以我想让它尽可能简单.有人可以阐明这些步骤来做到这一点吗?
I'm trying to learn JPA and I want create a simple Java command line app that will use JPA to query and update a database table. I mapped out the the simple code needed to do this. But I don't know how to configure the directory structure, where to place the persistence.xml file, packaging and so on. This is just a quick and dirty learning exercise so I want to keep this as simple as possible. Can someone spell out the steps in order to do this?
我正在使用Weblogic 10.3.
I'm using Weblogic 10.3.
推荐答案
persistence.xml放在与持久性类相同级别的META-INF
目录中. 这是一个示例一些有效和无效的配置.在我编写的非Java EE应用程序中,由于我的JPA类位于WEB-INF/classes/
中,因此我在WEB-INF/classes/META-INF/
中使用persistence.xml构建了JAR.
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 in WEB-INF/classes/META-INF/
, because my JPA classes are in WEB-INF/classes/
.
这篇关于如何配置和打包一个简单的Java应用程序以使用JPA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!