English 中文(简体)
DDL 产生和普遍的持久性。
原标题:DDL generation and general persistence.xml settings (OpenJPA)

<<>Summary

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.

<><>Problem>

页: 1 更具体地说,<代码>persistence.xml 注

  • 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)?

此外:

  • How are the DDL generation properties expressed in OpenJPA? I wasn t able to find them the OpenJPA User Guide.

<> 详情>

下面是EclipseLinkpersistence.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

<<><><><><>>>>><><><>>>>>

  • Does anyone know what the equivalent persistence.xml would look like for OpenJPA?
  • Alternatively, if anyone could point me to an OpenJPA tutorial that covers these issues that would be just as good
最佳回答

如果添加<条码>开放式jpa.jdbc.SynchronizeMappings 财产,如下文所示,开放式JPA将把所有表格、所有主要钥匙和所有外国钥匙自动化,与你的物体相匹配。

<property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)"/>

或者,你可以在TomEE中使用EclipseLink, 仅将EclipseLink jars添入<CATALINA_HOME>/lib/

http://openejb.apache.org/common-persistenceprovider-properties.html。 共同财产:

问题回答

Foreign key constraints

下一行不产生外国钥匙:

<property name="openjpa.jdbc.SynchronizeMappings" 
          value="buildSchema(ForeignKeys=true)"/>

只制作图表,删除数据库的内容。

但是,如果你想要创造外国钥匙,则使用以下路线:

<property name="openjpa.jdbc.SynchronizeMappings" 
          value="buildSchema(foreignKeys=true,schemaAction= dropDB,add )"/>
<property name="openjpa.jdbc.SchemaFactory" 
          value="native(foreignKeys=true)" />
<property name="openjpa.jdbc.MappingDefaults" 
          value="ForeignKeyDeleteAction=restrict, JoinForeignKeyDeleteAction=restrict"/>

See generated SQL

另一种方式是,如果你想看到“结构”的产出:

<property name="openjpa.Log" 
          value="DefaultLevel=TRACE,SQL=TRACE" />

。 为了了解托梅列公司的生成产出,你需要修改文档中的标识水平:loggin.properties, openjpa.level = FINEST


See more in





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签