【发布时间】:2010-11-26 03:36:00
【问题描述】:
每当对 JPA 实体类进行修改时,以下 sn -p 都会为特定数据库生成创建/删除 sql。
如何执行与“for”操作等效的操作,其中以下代码可用于为所有支持的数据库(例如 H2、MySQL、Postgres)生成 sql
目前每次生成sql文件都要修改db.groupId、db.artifactId、db.driver.version
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>hibernate3-maven-plugin</artifactId>
<version>${hibernate3-maven-plugin.version}</version>
<executions>
<execution>
<id>create schema</id>
<phase>process-test-resources</phase>
<goals>
<goal>hbm2ddl</goal>
</goals>
<configuration>
<componentProperties>
<persistenceunit>${app.module}</persistenceunit>
<drop>false</drop>
<create>true</create>
<outputfilename>${app.sql}-create.sql</outputfilename>
</componentProperties>
</configuration>
</execution>
<execution>
<id>drop schema</id>
<phase>process-test-resources</phase>
<goals>
<goal>hbm2ddl</goal>
</goals>
<configuration>
<componentProperties>
<persistenceunit>${app.module}</persistenceunit>
<drop>true</drop>
<create>false</create>
<outputfilename>${app.sql}-drop.sql</outputfilename>
</componentProperties>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate-core.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j-api.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-nop</artifactId>
<version>${slf4j-nop.version}</version>
</dependency>
<dependency>
<groupId>${db.groupId}</groupId>
<artifactId>${db.artifactId}</artifactId>
<version>${db.driver.version}</version>
</dependency>
</dependencies>
<configuration>
<components>
<component>
<name>hbm2cfgxml</name>
<implementation>annotationconfiguration</implementation>
</component>
<component>
<name>hbm2dao</name>
<implementation>annotationconfiguration</implementation>
</component>
<component>
<name>hbm2ddl</name>
<implementation>jpaconfiguration</implementation>
<outputDirectory>src/main/sql</outputDirectory>
</component>
<component>
<name>hbm2doc</name>
<implementation>annotationconfiguration</implementation>
</component>
<component>
<name>hbm2hbmxml</name>
<implementation>annotationconfiguration</implementation>
</component>
<component>
<name>hbm2java</name>
<implementation>annotationconfiguration</implementation>
</component>
<component>
<name>hbm2template</name>
<implementation>annotationconfiguration</implementation>
</component>
</components>
</configuration>
</plugin>
【问题讨论】: