0

I want to create my Database (MySQL) using my Java Spring boot @entities & classes defined already with all the required fields and associations. Is it possible to do automatically (By a make migration or migrate command mechanism) ? or do i have to explicitly write the SQL queries e.g the Create Table ones.

PS : tools such as flyway arent of a big help as they require to write SQL code despite defined JAVA Code. Thank you,

lopmkipm
  • 67
  • 2
  • 10

1 Answers1

0

Spring Boot Uses Hibernate under the hood as an ORM mapping tool.

Hibernate indeed has such a feature:

In plain hibernate:

hibernate.hbm2ddl.auto is the parameter that you're looking for: use the create as a value

Other values also can come handy, read this SO thread for more information

Spring boot names this parameter slightly different but the logic behind stays the same

Update 1

*Based on Op's comment:

Unfortunately I don't have any access to code that works with the relational databases. But given Spring boot driven application you probably already have src/main/resources/application.properties (or yaml).

So you should: Read the relevant chapter of spring boot configuration

Then,

In the application.properties (or yml) put

spring.jpa.hibernate.ddl-auto=create

And start the application. It should create the tables during the hibernate startup if everything else is configured correctly.

If

Mark Bramnik
  • 39,963
  • 4
  • 57
  • 97