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:
- Connect to
template1
database - Execute
CREATE DATABASE
newdb; - Reconnect to the newdb;
- 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.
精彩评论