2

私は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 でこれを行うにはどうすればよいですか?

プロパティを試してみました

<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}
4

1 に答える 1

3

で方言を指定できますpropertyfile。で宣言しますhibernate.properties

hibernate.dialect=org.hibernate.dialect.Oracle9Dialect

そして、次のように使用します。

<jpaconfiguration propertyfile="hibernate.properties"/>
于 2010-03-03T22:53:51.540 に答える