开发者

How do I get hibernate to execute CREATE DATABASE if necessary for postgresql when hibernate.hbm2ddl.auto is set to create

I am using spring-roo, gwt and hibernate to make a website. We are using the in memory 开发者_StackOverflow中文版database HyperSonic, but I am trying to switch to postgres.

Everything works fine if I used the jdbc3 driver. The only problem is I have to separately execute the CREATE DATABASE statement outside of hibernate before it will create the tables via [hibernate.hbm2ddl.auto](http://docs.jboss.org/hibernate/core/3.3/reference/en/html/session-configuration.html#configuration-optional) being set to create. Is their another option I can set to cause hibernate to do the CREATE DATABASE if necessary?


Not really. You have to do a CREATE DATABASE using a template database (normally template1). The normal sequence of events is:

  1. Connect to template1 database
  2. Execute CREATE DATABASE newdb;
  3. Reconnect to the newdb;
  4. Begin issuing DDL statements.

If you're interested in more information, look in to the specifics of how PostgreSQL completes the CREATE DATABASE and you'll understand why.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜