skip to Main Content

I have written the code. It goes like –

Here is my GitHub Repo – https://github.com/SuvamNaskar/spring-learn.git

spring.datasource.url=jdbc:mysql://${MYSQL_HOST:localhost}:2023/student?createDatabaseIfNotExist=true&useSSL=false
spring.datasource.username=root
spring.datasource.password=system32
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.data.jpa.repositories.enabled=true
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
spring.thymeleaf.check-template-location=false
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.defer-datasource-initialization= true
spring.jpa.open-in-view=false
logging.level.org.hibernate.SQL=DEBUG
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl

This is my application.properties file. I have tried every single thing I knew.

There is no error in the terminal <= Click here to view image

But no table is created. This is in MySQL WorkBench <= Click here to view image

I have tried to create the table from Spring JPA into MySQL

My expectation is, when I run the program if the table is not present then it should create the table.

2

Answers


  1. change this from "spring.jpa.hibernate.ddl-auto=create-drop" to "spring.jpa.hibernate.ddl-auto=update"

    Login or Signup to reply.
  2. Entity scan is incorrect @EntityScan(basePackages = {"com.springboot.Model"}) . it should be

    @EntityScan(basePackages = {"in.suvam.learn"})
    

    create-drop – The Hibernate will drop the database after all operations are completed. As per naveen’s comment, pls use update

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search