aspose file tools*
The moose likes Object Relational Mapping and the fly likes Hibernate: Generate the DDl to a output file using the update=true in hbm2ddl tool Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate: Generate the DDl to a output file using the update=true in hbm2ddl tool" Watch "Hibernate: Generate the DDl to a output file using the update=true in hbm2ddl tool" New topic
Author

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

sudipti mishra
Greenhorn

Joined: Aug 18, 2011
Posts: 2
Hi,

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

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.

Thanks,
SM


Arun Kumarr
Ranch Hand

Joined: May 16, 2005
Posts: 513

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

or

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


If you are not laughing at yourself, then you just didn't get the joke.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate: Generate the DDl to a output file using the update=true in hbm2ddl tool