When using Hibernate tools 3.2.0.beta8 to determine the database deltas using the update="true" option for hbm2ddl task, I am finding that the DDL is executed correctly and echoed to the screen, but is not saved in the outputfilename="schema_alter.sql".
I have had a look at the Code and it looks like currently there is no support for writing the deltas to a file.
Would any of the developers be kind enough to add this support ? it has also been requested on another thread. I think the code changes are very small :-
Hbm2DDLExporterTask
Code:
public void execute() {
if(schemaUpdate) {
SchemaUpdate update = new SchemaUpdate(parent.getConfiguration() );
update.execute(scriptToConsole, exportToDatabase);
}
else {
SchemaExport export = new SchemaExport(parent.getConfiguration() );
if(outputfileName!=null) {
export.setOutputFile(new File(getDestdir(),outputfileName).toString() );
}
if(delimiter!=null) {
export.setDelimiter(delimiter);
}
add a :-
update.setOutputFile(new File(getDestdir(),outputfileName).toString() );
to the first part of 'if' above and corresponding settor in SchemaUpdate, just like there is on the 'else' and SchemaExport.java , then
in the execute() of SchemaUpdate.java
Code:
String[] createSQL = configuration.generateSchemaUpdateScript( dialect, meta );
for ( int j = 0; j < createSQL.length; j++ ) {
final String sql = createSQL[j];
try {
if ( script ) {
System.out.println( sql );
}
if ( doUpdate ) {
log.debug( sql );
stmt.executeUpdate( sql );
}
}
catch ( SQLException e ) {
exceptions.add( e );
log.error( "Unsuccessful: " + sql );
log.error( e.getMessage() );
}
}
I guess we need some of the code like in the SchemaExport.java's to write formatted statements to a file writer.
Code:
String formatted = format( sql );
if ( delimiter != null ) {
formatted += delimiter;
}
if ( script ) {
System.out.println( formatted );
}
log.debug( formatted );
if ( outputFile != null ) {
fileOutput.write( formatted + "\n" );
}
If anyone could do this, it would be very much appreciated.