Skip to main content

Options for Database Intialization

DDL = Data Definition Lang DML = Data Manipulation Lang

Hibernate

  • Allows the database to be created from the JPA in memory
  • Hibernate property is set by the Spring property spring.jpa.hibernate.ddl-auto
  • Options are:
    • none - Hibernate does nothing
    • validate - Fail if there is a table or column missing
    • update - Automatically update database model by running ddl statements.*
    • create - Create tables everytime*
    • create-drop - Same as above except the table is dropped on termination*

*Use with cuation, not reccomended for all production systems

  • Spring Boot will use create-drop for embedded databases (hsql, h2, derby) or none otherwise
  • Data can be loaded from import.sql
    • Must be on the root of class path
    • Only executed if set to create or create-drop

Spring JDBC

  • Spring DataSource initializer via Spring Boot will by default load schema.sql and data.sql from the root of the classpath
  • Spring Boot will also load from schema-${platform}
  • May conflict with Hibernate's DDL Auto property
    • Should use none or validate