• Post Reply Bookmark Topic Watch Topic
  • New Topic

Hibernate: Generate the DDl to a output file using the update=true in hbm2ddl tool  RSS feed

sudipti mishra
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I am trying to export the generated DDL to a output file instead of directly showing in command prompt for hbm2ddl.auto=update(using automatic schema generation).

I know this may not be good idea to generate the schema using this for production database. I have already gone thru several threads that talk about it.

I am trying to use this for development/test databases.

But, the challenge I am facing here is it's not sending out the generated DDL to a output file even though I am using the "outputfilename" attribute in hbm2ddl
exporter. (as per this http://docs.jboss.org/tools/2.1.0.Beta1/hibernatetools/html/ant.html)

Here is how my build.xml looks like. I am using the Hibernate's Jpa configuration.

<taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask" classpathref="classpath.hibernate" />

<target name="db_update_schema_sql" depends="db_config" description="create SQL script for updating schema">
<hibernatetool destdir="${out.dir}">
<jpaconfiguration persistenceunit="${persistence.unit.name}"/>
<classpath path="${build.classes.dir}"/>
<hbm2ddl export="false" create="false" update="true" drop="false" outputfilename="update.sql" delimiter=";" format="true"/>
</hibernatetool> </target>

<target name="db_full_update" depends="db_config" description="Updates database">
<antcall target="db_update_schema_sql" />

The "update.sql" is never created/updated when I set the update="true". It only creates/update when I use either create="true" or drop="true" or both.

I digged little bit into this. I found couple of issues related to this in Hibernate Jira. It still says it's unresolved. There is a patch available for this. Not sure
whether someone used this patch.

https://hibernate.onjira.com/browse/HHH-1186 https://hibernate.onjira.com/browse/HBX-757

I would really appreciate if someone using this update="true" feature to generate the ddl directly to a file explain to me how they have done it.

Also, if you use the patch for this, can you let me know how you applied the patch to the existing Jar file.


Arun Kumarr
Ranch Hand
Posts: 662
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not worked this specific, but a dirty solution would be to output the console to a file. Can you try this?

C:\Users\arunkumarr> build.xml >> myLog.txt


C:\Users\arunkumarr> build.xml > myLog.txt

Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!