PostgreSQL + Hibernate + Spring auto create database

后端 未结 6 1302
时光说笑
时光说笑 2020-12-18 07:08

I\'m working with PostgreSQL and Spring 4 and want my app auto create database when it running.

My Entity Class is:

@Entity
@Table(name = \"user\", s         


        
6条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-18 07:50

    Postgres unlike mysql does not support Create Database If not exist.

    Thus changing hibernate.hbm2ddl.auto=create and changing URL jdbc.url=jdbc:postgresql://localhost/database?createDatabaseIfNotExist=true won't work for you.

    However you can try simulating the behavior as in below questions:

    Create Postgres database on the fly, if it doesn't exists using Hibernate

    Simulate CREATE DATABASE IF NOT EXISTS for PostgreSQL?

提交回复
热议问题