PostgreSQL + Hibernate + Spring auto create database

后端 未结 6 1304
时光说笑
时光说笑 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:45

    The property hibernate.hbm2ddl.auto will do the trick for you. It automatically validates or exports schema DDL to the database when the SessionFactory is created. With create-drop, the database schema will be dropped when the SessionFactory is closed explicitly.

    Hibernate can accept these options for the above property.

    validate: validate the schema, makes no changes to the database.

    update: update the schema.

    create: creates the schema, destroying previous data.

    create-drop: drop the schema at the end of the session.

提交回复
热议问题