DDL生成和常规persistence.xml设置(OpenJPA) [英] DDL generation and general persistence.xml settings (OpenJPA)
问题描述
摘要
我正在尝试运行Java Web应用程序JPA 2.0示例。 示例应用程序编写为在 Glassfish
,使用 EclipseLink
作为JPA提供程序。
我想将其转换为在 TomEE
中运行,其中 OpenJPA
作为JPA提供商,但我可以启动和运行 OpenJPA
的任何详细教程。
I'm trying to run a Java web application JPA 2.0 example. The example application was written to run in Glassfish
, using EclipseLink
as JPA provider.
I would like to convert it to run in TomEE
with OpenJPA
as the JPA provider, but I can't any detailed tutorials for getting up and running with OpenJPA
.
问题
我无法转换 persistence.xml
以使用 OpenJPA
而不是 EclipseLink
。更具体地说,给定的 persistence.xml
没有指定:
I'm having trouble converting persistence.xml
to work with OpenJPA
instead of EclipseLink
. More specifically, the given persistence.xml
doesn't specify:
-
实体
类。这些是必要的吗? - 所需的JPA提供商。容器会默认为什么吗?
- JDBC驱动程序。如何指定内存中数据库(仅用于初始测试目的)?
Entity
classes. Are these necessary?- The desired JPA provider. Will the container default to something?
- The JDBC driver. How do I specify an "in-memory" DB (just for initial testing purposes)?
另外:
- 如何在OpenJPA中表达DDL生成属性?我无法找到它们 OpenJPA用户指南。
- How are the DDL generation properties expressed in OpenJPA? I wasn't able to find them the OpenJPA User Guide.
详细信息
以下是EclipseLink persistence.xml
:
Below is the EclipseLink 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="order" transaction-type="JTA">
<jta-data-source>jdbc/__default</jta-data-source>
<properties>
<property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
<property name="eclipselink.ddl-generation.output-mode"
value="both" />
</properties>
</persistence-unit>
</persistence>
我有以下实体
类:
-
order.entity.LineItem
-
order.entity.LineItemKey
-
order.entity.Order
-
order.entity.Part
-
order.entity.PartKey
-
order.entity.Vendor
-
order.entity.VendorPart
order.entity.LineItem
order.entity.LineItemKey
order.entity.Order
order.entity.Part
order.entity.PartKey
order.entity.Vendor
order.entity.VendorPart
问题
- 有没有人知道OpenJPA的等效persistence.xml是什么样的?
- 或者,如果有人能指出我的话一个OpenJPA教程,涵盖了一些同样好的问题
推荐答案
如果你添加了 openjpa.jdbc.SynchronizeMappings
属性如下所示OpenJPA将自动创建所有表格,所有主键和所有外键完全匹配您的对象
If you add the openjpa.jdbc.SynchronizeMappings
property as shown below OpenJPA will auto-create all your tables, all your primary keys and all foreign keys exactly to match your objects
<property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)"/>
或者,只需将EclipseLink jar添加到,就可以在TomEE中使用EclipseLink < CATALINA_HOME> / lib /
Alternatively, you can use EclipseLink in TomEE by just adding the EclipseLink jars to <CATALINA_HOME>/lib/
请参阅此处 Common PersistenceProvider属性
这篇关于DDL生成和常规persistence.xml设置(OpenJPA)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!