简体   繁体   English

当 hibernate.hbm2ddl.auto 设置为创建时,如果 postgresql 需要,我如何让 hibernate 执行 CREATE DATABASE

[英]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-roogwthibernate来制作网站。 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:正常的事件顺序是:

  1. Connect to template1 database连接到template1数据库
  2. Execute CREATE DATABASE newdb;执行CREATE DATABASE新数据库;
  3. Reconnect to the newdb;重新连接到新数据库;
  4. Begin issuing 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.

相关问题 hibernate.hbm2ddl.auto值来执行这两个操作,即在数据库架构上创建/更新? - hibernate.hbm2ddl.auto value to do both the operations i.e create/update on database schema? hibernate.hbm2ddl.auto Hibernate如何决定何时创建或更新ddl? - hibernate.hbm2ddl.auto how does Hibernate decide when to create or update the ddl? hibernate.hbm2ddl.auto create-drop with production Database - hibernate.hbm2ddl.auto create-drop with production Database “ hibernate.hbm2ddl.auto”属性/创建和更新 - “hibernate.hbm2ddl.auto” property / create&update hibernate.hbm2ddl.auto =create(不创建表) - hibernate.hbm2ddl.auto =create (not creating Table) hibernate.hbm2ddl.auto =创建不清除现有数据 - hibernate.hbm2ddl.auto=create not clearing out existing data “hibernate.hbm2ddl.auto”不建表? - “hibernate.hbm2ddl.auto” does not create a table? hibernate.hbm2ddl.auto属性使用create创建表,但不使用update创建表 - hibernate.hbm2ddl.auto property creates table with create but not with update 找不到与hibernate.hbm2ddl.auto创建的表 - Table not found with hibernate.hbm2ddl.auto create 在多个分支上使用共享dev数据库时,如何防止Hibernate hibernate.hbm2ddl.auto错误? - How do I prevent Hibernate hibernate.hbm2ddl.auto errors when using a shared dev DB on multiple branches?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM