I'm trying to propagate the schema from the Hibernate configuration to the RDBMS. The code runs without any error message but the database doesn't get updated.
Any hints ? Thank you !
Update That is hibernate-core only with a HSQL database.
Update 2 Yes, i should use SchemaExport (i'm away from hibernate a while ),but it don't flush to the database. It is a HSQL in-process database (jdbc:hsqldb:file:config/config).
Update 3 Something does not work with HSQL, trying now with MySQL and all works fine !
public static void exportSchema() {
new SchemaExport(hbConfig).create(true, true);
}
public static void exportSchemaXXX() {
// sessionFactory and hbConfig defined in the class
Session sess = sessionFactory.openSession();
sess.doWork(new Work() {
public void execute(java.sql.Connection conn) throws SQLException {
System.err.println("work");
try {
Class dialect = Class.forName(hbConfig.getProperty("hibernate.dialect"));
String[] lines = hbConfig.generateSchemaCreationScript((Dialect) dialect.newInstance());
for (String s : lines) {
System.err.println(s);
Statement stm = conn.createStatement();
stm.execute(s);
}
} catch (Exception ex) {
System.err.println("Error: " + ex);
}
}
});
sess.flush();
sess.close();
}