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 deprecated ?
What is replacement ?
These classes are part of the hibernate-ant module: https://search.maven.org/artifact/org.hibernate.orm/hibernate-ant/6.1.4.Final/jar