wil*_*824 33 java persistence entity code-generation jpa-2.0
如何从现有数据库生成符合JPA2的@Entity?
我发现了这个:问题
仍然不清楚JBoss是否会生成兼容的JPA2,而且我想知道是否有独立于供应商的方式来做到这一点.
Hus*_*ala 17
尝试使用OPENJPA反向映射工具.它们提供了更多的设施,并且易于配置.这个例子将澄清.
如果您使用maven作为构建工具,请将此条目添加到您的pom.xml中
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2</version>
<configuration>
<mainClass>org.apache.openjpa.jdbc.meta.ReverseMappingTool</mainClass>
<commandlineArgs>
-directory src/main/java -accessType fields
-useGenericCollections true -package org.yourproject.model
-metadata none -annotations true
-innerIdentityClasses false -useBuiltinIdentityClass false
-primaryKeyOnJoin false
</commandlineArgs>
<includePluginDependencies>true</includePluginDependencies>
</configuration>
<dependencies>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.0.CR3</version>
</dependency>
<dependency>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa-all</artifactId>
<version>2.0.1</version>
</dependency>
</dependencies>
</plugin>
Run Code Online (Sandbox Code Playgroud)
还要在persistence.xml中添加以下属性,该属性位于资源的META-INF文件夹中.这些将由openjpa工具利用以建立与数据库的连接.
<properties>
<property name="openjpa.ConnectionUserName" value="${db.username}"/>
<property name="openjpa.ConnectionPassword" value="${db.password}"/>
<property name="openjpa.ConnectionURL" value="${db.url}"/>
<property name="openjpa.ConnectionDriverName" value="${db.driver.class}"/>
</properties>
Run Code Online (Sandbox Code Playgroud)
要生成实体文件,只需使用mvn org.codehaus.mojo:exec-maven-plugin:java在项目目录中启动maven目标 ,它将在所需位置生成文件.
| 归档时间: |
|
| 查看次数: |
86450 次 |
| 最近记录: |