[英]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.我正在使用spring-roo 、 gwt和hibernate来制作网站。 We are using the in memory database HyperSonic, but I am trying to switch to postgres .
我们正在使用 memory 数据库 HyperSonic,但我正在尝试切换到postgres 。
Everything works fine if I used the jdbc3 driver .如果我使用jdbc3 驱动程序,一切正常。 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.唯一的问题是我必须在 hibernate 之外单独执行
CREATE DATABASE
语句,然后才能通过[hibernate.hbm2ddl.auto](http://docs.jboss.org/hibernate/core/3.3/reference/en/html/session-configuration.html#configuration-optional)
被设置为创建。 Is their another option I can set to cause hibernate to do the CREATE DATABASE
if necessary?我可以设置他们的另一个选项以使 hibernate 在必要时执行
CREATE DATABASE
吗?
Not really.并不真地。 You have to do a
CREATE DATABASE
using a template database (normally template1
).您必须使用模板数据库(通常是
template1
)进行CREATE DATABASE
。 The normal sequence of events is:正常的事件顺序是:
template1
databasetemplate1
数据库CREATE DATABASE
newdb;CREATE DATABASE
新数据库;DDL
statements.DDL
语句。 If you're interested in more information, look in to the specifics of how PostgreSQL completes the CREATE DATABASE
and you'll understand why.如果您对更多信息感兴趣,请查看 PostgreSQL 如何完成
CREATE DATABASE
的细节,您就会明白其中的原因。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.