Replacing SchemaExport(Configuration) in Hibernate 5

后端 未结 3 1963
渐次进展
渐次进展 2020-12-16 03:33

While migrating from Hibernate 4 to 5 I came across the deprecation and eventual removal of the SchemaExport(Configuration) constructor. What is a good alternat

3条回答
  •  无人及你
    2020-12-16 03:49

    Distilling from other answers, I had to do the followings:

            StandardServiceRegistry standardRegistry = new StandardServiceRegistryBuilder()
                .applySetting("hibernate.hbm2ddl.auto", "create")
                .applySetting("hibernate.dialect", "org.hibernate.dialect.MySQLDialect")
                .applySetting("hibernate.id.new_generator_mappings", "true")
                .build();
        MetadataSources sources = new MetadataSources(standardRegistry);
        managedClassNames.forEach(sources::addAnnotatedClass);
        MetadataImplementor metadata = (MetadataImplementor) sources
                .getMetadataBuilder()
                .build();
    
        SchemaExport export = new SchemaExport(metadata);
    

    Hopefully that help

提交回复
热议问题