문제

I have parametrized persistence.xml. I am trying to generate ddl schema using hbm2ddl. How can i pass parameters to this tool ?

My persistence.xml looks like

<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}"/>

When i start server parameter values are passed as JAVA_OPTS (using -Dpersistence.dialect=value). And it works well.

How do i do this with hbm2ddl ?

I tried 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>

But it does not get this value. It shows me error.

build.xml:160: org.hibernate.HibernateException: Dialect class not found: ${persistence.dialect}
도움이 되었습니까?

해결책

You could specify the dialect via propertyfile. Declare it in a hibernate.properties:

hibernate.dialect=org.hibernate.dialect.Oracle9Dialect

And use it like this:

<jpaconfiguration propertyfile="hibernate.properties"/>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top