Andrei Pall

Linux Software Engineering

Spring Boot Configuration

Hibernate is the most popular implementation of JPA. The Java Persistence API provides Java developers with an api for mapping java objects to relational data. In this article, you will learn about Spring Boot database configuration.

Configure application.properties:

server.port=8000
spring.datasource.url=jdbc:mysql://localhost/DatabaseDemo
spring.datasource.username=root
spring.datasource.password=eclipse
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.hibernate.ddl-auto=create-drop

#spring.jpa.show-sql=true

#Show SQL
spring.jpa.properties.hibernate.show_sql=true

#Format SQL
spring.jpa.properties.hibernate.format_sql=true

#Show bind values
logging.level.org.hibernate.type.descriptor.sql=trace

Restart the app and you are ready!
Things to note:

  • Spring Boot chooses a default value for you based on whether it thinks your database is embedded (default create-drop) or not (default none).
  • spring.jpa.hibernate.ddl-auto is the setting to perform SchemaManagementTool actions automatically
    • none: No action will be performed.
    • create-only: Database creation will be generated.
    • drop: Database dropping will be generated.
    • create: Database dropping will be generated followed by database creation.
    • validate: Validate the database schema
    • update: Update the database schema
  • Reference: https://docs.jboss.org/hibernate/orm/5.2/userguide/html_single/Hibernate_User_Guide.html#configurations-hbmddl