DDL生成和常规persistence.xml设置(OpenJPA)

Ale*_*uch 8 java jpa openjpa openejb apache-tomee

摘要

我正在尝试运行Java Web应用程序JPA 2.0示例.该示例应用程序被写入到运行Glassfish,使用EclipseLink作为JPA提供商.我想将其转换为运行在TomEEOpenJPA作为JPA提供者,但我不能为起床,并与正在运行的任何详细的教程OpenJPA.

问题

我很难转换persistence.xml到工作OpenJPA而不是EclipseLink.更具体地说,给定的persistence.xml未指定:

  • Entity类.这些必要吗?
  • 所需的JPA提供者.容器会默认为什么吗?
  • JDBC驱动程序.如何指定"内存中"DB(仅用于初始测试目的)?

也:

细节

以下是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>
Run Code Online (Sandbox Code Playgroud)

我有以下Entity课程:

  • 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教程,涵盖这些问题,那将是同样好的

Dav*_*ins 7

如果您添加openjpa.jdbc.SynchronizeMappings如下所示的属性,OpenJPA将自动创建所有表,所有主键和所有外键完全匹配您的对象

<property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)"/>
Run Code Online (Sandbox Code Playgroud)

或者,您可以通过添加EclipseLink jar来在TomEE中使用EclipseLink <CATALINA_HOME>/lib/

在这里引用Common PersistenceProvider属性