我已参数化 persistence.xml。我正在尝试使用 hbm2ddl 生成 ddl 架构。我如何向该工具传递参数?
我的 persistence.xml 看起来像
<property name="hibernate.connection.driver_class" value="${persistence.connection.driver.class}"/>
<property name="hibernate.dialect" value="${persistence.dialect}"/>
<property name="hibernate.connection.password" value="${persistence.password}"/>
<property name="hibernate.connection.username" value="${persistence.username}"/>
当我启动服务器时,参数值作为 JAVA_OPTS 传递(使用 -Dpersistence.dialect=value)。而且效果很好。
如何使用 hbm2ddl 执行此操作?
我尝试过属性(property)
<hibernatetool destdir="${gensrc.sql.dir}">
<property key="persistence.dialect" value="org.hibernate.dialect.Oracle9Dialect"/>
<jpaconfiguration persistenceunit="${persistence.unit.name}" />
<classpath>
<!-- it is in this classpath you put your classes dir,
and/or jpa persistence compliant jar -->
<path location="${build.classes.dir}" />
</classpath>
<hbm2ddl export="false" drop="true" outputfilename="create_${ant.project.name}.sql" format="true" haltonerror="true" />
</hibernatetool>
但是它没有得到这个值。它向我显示错误。
build.xml:160: org.hibernate.HibernateException: Dialect class not found: ${persistence.dialect}
最佳答案
您可以通过propertyfile
指定方言。在 hibernate.properties
中声明它:
hibernate.dialect=org.hibernate.dialect.Oracle9Dialect
并像这样使用它:
<jpaconfiguration propertyfile="hibernate.properties"/>
关于java - 将参数传递给 hbm2ddl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2371747/