-1

There is a web application using Spring Boot and JpaRepository interface to perform database queries. I want the application to be able to create tables in the database on its own at startup. How can this be done? Maybe I need to use Hibernate or something else for this? without xml

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Kejnam
  • 1
  • 2

3 Answers3

0

You need to add the JPA configurations to your application.properties file. Example of MySQL is below:

spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect
spring.jpa.hibernate.ddl-auto=update
spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/test
spring.datasource.username=test
spring.datasource.password=

you can see some explanation here. Also, read about spring boot and JPA here.

Prog_G
  • 1,539
  • 1
  • 8
  • 22
0

You can use Liquibase with Spring Boot (see docs). It will be possible to create and update your database tables at startup.

VAG
  • 69
  • 1
  • 3
0

Incase you want to use MySQL use the previous answer and if needed to use postgres then use the code given below.

spring.datasource.platform=postgres
spring.datasource.url=jdbc:postgresql://localhost:5432/schema_name
spring.datasource.username=postgres
spring.datasource.password=postgres
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQL95Dialect