I'm updating a Hibernate 3 project to Hibernate 6. At some point of the code, a schema with certain mappings is created using:
import org.hibernate.cfg.Configuration;
import org.hibernate.tool.hbm2ddl.SchemaUpdate;
public class SchemaGenerator {
private void create() {
SchemaUpdate schemaUpdate = new SchemaUpdate(getConfig());
schemaUpdate.execute(false, true);
}
private Configuration getConfig() {
if (cfg == null) {
cfg = new Configuration();
cfg.setProperty("hibernate.connection.driver_class", driverClassName);
cfg.setProperty("hibernate.connection.url", url);
cfg.setProperty("hibernate.connection.username", username);
cfg.setProperty("hibernate.connection.password", password);
cfg.setProperty("hibernate.dialect", hibernateDialect);
cfg.setProperty("hibernate.jdbc.batch_size", Integer.toString(CommonConstants.JDBC_BATCH_SIZE));
cfg.setProperty("hibernate.connection.provider_class", "org.hibernate.connection.C3P0ConnectionProvider");
cfg.setProperty("hibernate.connection.autocommit", "true");
cfg.setProperty("hibernate.default_schema", username);
cfg.setProperty("hibernate.hbm2ddl.auto", "create");
cfg.configure(configFile);
}
return cfg;
}
}
My XML configuration file looks like:
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<mapping class="org.application.hibernate.Table"/>
<session-factory>
<hibernate-configuration>
The problem is that the SchemaUpdate constructor no longer accepts any parameters, and I can't find how to pass the XML configuration to that object as well. You can see on Hibernate 3 hbm2ddl.SchemaUpdate docs how this was valid.
I've been able to see on the Hibernate docs that automatic schema generation is still supported, but the examples are not really explaining what I'm looking for.