不用连接用Hibernate 4生成DDL
Generate DDL with Hibernate 4 without connection
我曾经使用 hibernate3-maven-plugin 和 Hibernate 3 生成 DDL。
自从我切换到 Hibernate 4 我不能再使用这个插件了。
如果不连接到实际的 PostgreSQL 数据库,我找不到从映射生成 DDL 的方法。
我尝试了很多东西(包括 hibernate4-maven-plugin 来自 de.juplo 和 this)但我觉得每个方法都需要一个数据库连接。
有没有一种(好的)方法可以在没有连接的情况下在 Hibernate 4 中生成 DDL?
我可以用这种方式生成我的 DDL 脚本:
<plugin>
<groupId>de.juplo</groupId>
<artifactId>hibernate4-maven-plugin</artifactId>
<version>1.1.1</version>
<executions>
<execution>
<goals>
<goal>export</goal>
</goals>
</execution>
</executions>
<configuration>
<hibernateDialect>org.hibernate.dialect.PostgreSQLDialect</hibernateDialect>
<!-- I want generate the schemas for these dialects too, at same time... -->
<!-- <hibernateDialect>org.hibernate.dialect.Oracle10gDialect</hibernateDialect> -->
<!-- <hibernateDialect>org.hibernate.dialect.SQLServerDialect</hibernateDialect> -->
<target>SCRIPT</target>
</configuration>
</plugin>
我不需要任何连接,我只指定 SQL 方言。使用 mvn clean package
Maven 将脚本放在目标文件夹中。
这是我的persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1"
xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="primary">
<jta-data-source>java:jboss/datasources/library.backendDS</jta-data-source>
<properties>
<!-- Properties for Hibernate -->
<property name="hibernate.hbm2ddl.auto" value="validate" />
<property name="hibernate.show_sql" value="false" />
</properties>
</persistence-unit>
</persistence>
我曾经使用 hibernate3-maven-plugin 和 Hibernate 3 生成 DDL。 自从我切换到 Hibernate 4 我不能再使用这个插件了。
如果不连接到实际的 PostgreSQL 数据库,我找不到从映射生成 DDL 的方法。
我尝试了很多东西(包括 hibernate4-maven-plugin 来自 de.juplo 和 this)但我觉得每个方法都需要一个数据库连接。
有没有一种(好的)方法可以在没有连接的情况下在 Hibernate 4 中生成 DDL?
我可以用这种方式生成我的 DDL 脚本:
<plugin>
<groupId>de.juplo</groupId>
<artifactId>hibernate4-maven-plugin</artifactId>
<version>1.1.1</version>
<executions>
<execution>
<goals>
<goal>export</goal>
</goals>
</execution>
</executions>
<configuration>
<hibernateDialect>org.hibernate.dialect.PostgreSQLDialect</hibernateDialect>
<!-- I want generate the schemas for these dialects too, at same time... -->
<!-- <hibernateDialect>org.hibernate.dialect.Oracle10gDialect</hibernateDialect> -->
<!-- <hibernateDialect>org.hibernate.dialect.SQLServerDialect</hibernateDialect> -->
<target>SCRIPT</target>
</configuration>
</plugin>
我不需要任何连接,我只指定 SQL 方言。使用 mvn clean package
Maven 将脚本放在目标文件夹中。
这是我的persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1"
xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="primary">
<jta-data-source>java:jboss/datasources/library.backendDS</jta-data-source>
<properties>
<!-- Properties for Hibernate -->
<property name="hibernate.hbm2ddl.auto" value="validate" />
<property name="hibernate.show_sql" value="false" />
</properties>
</persistence-unit>
</persistence>