gpt4 book ai didi

java - 将参数传递给 hbm2ddl

转载 作者:行者123 更新时间:2023-12-04 06:57:32 27 4
gpt4 key购买 nike

我已经参数化了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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com