Hibernate 6 SchemaExport class not found
Asked Answered
S

2

8

I use code like to export JPA entities schema DDL :

import org.hibernate.tool.hbm2ddl.SchemaExport;
import org.hibernate.tool.hbm2ddl.SchemaUpdate;

public class HibernateQueryGenerator {
    public static void main(String[] args) {
//        createSchema();
        updateSchema();
    }

    private static void addEntityClass(MetadataSources metadata) {
        // Scan entity packages and use : 
        // metadata.addAnnotatedClass(...);
    }

    private static void updateSchema() {
        MetadataSources metadata = getMetadataSources();
        SchemaUpdate schemaUpdate = new SchemaUpdate();
        schemaUpdate.setHaltOnError(true);
        schemaUpdate.setFormat(false);
        schemaUpdate.setDelimiter(";");
        schemaUpdate.execute(EnumSet.of(TargetType.STDOUT), metadata.buildMetadata());
    }

    private static void createSchema() {
        MetadataSources metadata = getMetadataSources();
        SchemaExport schemaExport = new SchemaExport();
        schemaExport.setHaltOnError(true);
        schemaExport.setFormat(false);
        schemaExport.setDelimiter(";");
        schemaExport.execute(EnumSet.of(TargetType.STDOUT), SchemaExport.Action.CREATE, metadata.buildMetadata());
    }

    private static MetadataSources getMetadataSources() {
        MetadataSources metadata = new MetadataSources(
                new StandardServiceRegistryBuilder()
                        .applySettings(getSettings())
                        .build());
        addEntityClass(metadata);
        return metadata;
    }

    private static Map<String, String> getSettings() {
        Map<String, String> settings = new HashMap<>();
        settings.put("connection.driver_class", "org.postgresql.Driver");
        settings.put("dialect", "org.hibernate.dialect.PostgreSQL10Dialect");
        settings.put("hibernate.connection.url", "jdbc:postgresql://172.22.0.3:5432/tutorial");
        settings.put("hibernate.connection.username", "admin");
        settings.put("hibernate.connection.password", "adminpass");
        return settings;
    }
}         

I can not found SchemaExport and SchemaUpdate classes in Hibernate 6 .
is this classes depricated ?
What is replacement ?

Selestina answered 17/10, 2022 at 9:38 Comment(1)
Yes, I guess it have been removed from version 6, although I didn't find clue regarding this. Maybe this document can help you: docs.jboss.org/hibernate/orm/current/userguide/html_single/…Chenille
J
12

These classes are part of the hibernate-ant module: https://search.maven.org/artifact/org.hibernate.orm/hibernate-ant/6.1.4.Final/jar

Jingo answered 17/10, 2022 at 18:9 Comment(0)
M
2

You should use these dependencies if you are using hibernate 6 +

implementation 'org.hibernate.tool:hibernate-tools-orm:6.4.1.Final'
implementation 'org.hibernate.tool:hibernate-tools-utils:6.4.1.Final'
Monohydroxy answered 10/1 at 10:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.