problem with hsqldb database specificaly table dropping, using hsqldb/hibernate with my maven project
I am very new to this. And I am trying to configure a net-beans Maven project with hsqldb and hibernate. I have set up the database and I am able to save some data to the database. I am using the file mode. and this is my connection url
"jdbc:hsqldb:file:C:/data/findb"
however, the problem I am having is my database tables will be dropped at every execution and re-created brand new. I don't want this to happen. I want to create the tables only once and be able to update it afterwards.
Here is a snippet of my configuration file
boolean found = false;
String URL = "jdbc:hsqldb:file:C:/data/findb";
Configuration cfg = new Configuration();
if (!found) {
cfg.setProperty("hibernate.hbm2ddl.auto", "create");
} else {
cfg.setProperty("hibernate.hbm2ddl.auto", "update");
}
cfg.setProperty("hibernate.connection.driver_class",
"org.hsqldb.jdbcDriver");
cfg.setProperty("hibernate.connection.url", URL);
cfg.setProperty("hibernate.connection.use开发者_JAVA百科rname", "sa");
cfg.setProperty("hibernate.connection.password", "1234");
cfg.setProperty("hibernate.connection.pool_size", "20");
// cfg.setProperty("hibernate.connection.hsqldb.default_table_type",
// "cached");
sessionFactory = cfg.configure().buildSessionFactory();
And to my understanding that bit should have prevented the dropping of tables at each creation since I use the if-else statement to create if doesn't exist and update if it does.
This is how mydb.log starts
/*C4*/SET SCHEMA PUBLIC
drop table FinPlan if exists
drop table PersonalAssets if exists
drop table TB_UNIQUEID if exists
What am I missing?? any help will be appreciated. Thank you in advance.
The hibernate.hbm2ddl.auto = create will automatically recreate your tables at each executions. Since you set found to false, hibernate.hbm2ddl.auto will always be "create"
精彩评论