我正在尝试将模式从 Hibernate 配置传播到 RDBMS。代码运行时没有任何错误消息,但数据库没有更新。
有什么提示吗?谢谢 !
更新仅具有 HSQL 数据库的休眠核心。
更新 2是的,我应该使用 SchemaExport(我暂时远离休眠),但它不会刷新到数据库。它是一个 HSQL 进程内数据库 (jdbc:hsqldb:file:config/config)。
更新 3有些东西不适用于 HSQL,现在尝试使用 MySQL,一切正常!
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();
}