Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Ant task now appends to current file
PostPosted: Tue Mar 14, 2017 1:06 pm 
Newbie

Joined: Thu Dec 14, 2006 6:42 am
Posts: 15
I've been using the ant task to generate a schema.sql file for years.
I recently upgraded from Hibernate 4 to 5 to find that now the task always appends to any existing file.
I traced the behavior to the org.hibernate.tool.schema.internal.exec.ScriptTargetOutputToFile class:

Code:
   @SuppressWarnings("ResultOfMethodCallIgnored")
   static Writer toFileWriter(File file) {
      try {
         if ( ! file.exists() ) {
            // best effort, since this is very likely not allowed in EE environments
            log.debug( "Attempting to create non-existent script target file : " + file.getAbsolutePath() );
            if ( file.getParentFile() != null ) {
               file.getParentFile().mkdirs();
            }
            file.createNewFile();
         }
      }
      catch (Exception e) {
         log.debug( "Exception calling File#createNewFile : " + e.toString() );
      }
      try {
         return new FileWriter( file, true );
      }
      catch (IOException e) {
         throw new SchemaManagementException( "Unable to open specified script target file for writing : " + file, e );
      }
   }



As you see, the FileWriter is created with a "true" second parameter, which means "append".
Shouldn't this be corrected or maybe offered as an option of the ant task?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.