Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have the following hibernate.cfg.xml file

enter image description here

The problem, when I run the migration, the schema is not getting created in the database. I would like to create the schema from scratch. It only generates the script.sql file.

This I the main app file

public class DatabaseMigration {


    public static void main(String[] args){

        StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().configure("/META-INF/hibernate.cfg.xml").build();
        Metadata meta = new MetadataSources(ssr).getMetadataBuilder().build();

        SchemaExport schemaExport = new SchemaExport();
        schemaExport.setHaltOnError(true);
        schemaExport.setFormat(true);
        schemaExport.setDelimiter(";");
        schemaExport.setOutputFile("db-schema.sql");
        schemaExport.createOnly(EnumSet.of(TargetType.SCRIPT), meta);
}
}
question from:https://stackoverflow.com/questions/65945475/hibernate-does-not-create-schema-on-an-empty-databse

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
253 views
Welcome To Ask or Share your Answers For Others

1 Answer

Thanks, guys, I have found the mistake.

schemaExport.createOnly(EnumSet.of(TargetType.SCRIPT), meta); was the problem

the target only specifies SCRIPT.

I have replaced it with DATABASE and it works.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...