2
我有參數化persistence.xml。我正在嘗試使用hbm2ddl生成ddl模式。我怎樣才能將參數傳遞給這個工具?將參數傳遞給hbm2ddl
我的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 =值)。它運作良好。
我如何用hbm2ddl做到這一點?
我試圖財產
<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}
感謝帕斯卡。我指的是https://www.hibernate.org/hib_docs/tools/reference/en/html/ant.html 我如何使用螞蟻做到這一點?我的意思是你能指出我在哪裏我應該在中指定這些屬性 謝謝。 –
2010-03-04 12:30:09
@Jigar抱歉,錯誤的鏈接。我已經更新了與其他人的建議。 – 2010-03-04 14:59:16
再次感謝。有效。 (第一)。 (jpa配置不支持prop屬性。) 小問題仍然存在。使參數化persistence.xml的目的是在運行時更改此值。所以如果想爲oracle生成ddl,我可以用方言指定一個參數,並生成ddl。在這裏我必須用hibernate.dialect = oracle.driver指定一個文件。我現在已經完成了這個工作。感謝您的回覆。 – 2010-03-08 13:57:05