Home > database >  Springboot @entity create table vs flyway create table
Springboot @entity create table vs flyway create table

Time:11-10

When we use Springboot (without flyway dependency)

Once we define an object model and mark it with @Entity tag, and run the application Seems spring boot will automatically create a table in a database.

But when we add flyway dependency, when we run the application SpringBoot won't create the table, instead, it throws me an error. So the only fix is to create a table in the flyway. Does anyone know why this happens?

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: missing table [singer]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1753) ~[spring-beans-6.0.0-RC3.jar:6.0.0-RC3]

CodePudding user response:

You might want to set this variable as such in application.yml.

spring:
  jpa:
    hibernate:
      ddl-auto: update
  • Related