0

I am using spring-roo, gwt and hibernate to make a website. We are using the in memory 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?

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Sean, I understand postgresql used template1 as the model database, as SQL Server uses the database called model. However, I fail to understand why hibernate cannot be configured to do the same thing if the username and password provided in the config file has the appropiate permissions. I would not do that on a production database for security reasons, but that is a different discussion.
Ah! I misunderstood your question then and I'm not sure. My guess is that because you have to change databases, you need different JDBC connections in order to clear out any potentially cached JDBC information. There isn't anything magical about template1 so the JDBC driver could very well slurp in potentially stale schema information. Beyond that, I'm going to have to feign ignorance.
The problem with Hibernate is, that it was developed for server applications, where you expect that a database admin would make his hands dirty by creating a database manually (or by a script). Indeed I use Postgresql in a java desktop application and I encountered the very same problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.