0

I am finding the following difficulties trying to configure Spring Data JPA into my Spring Boot project.

I have the following problem related to the application.properties file. This is my original application.properties file content:

spring:
  application:
    name: Spring Boot Excel API
  datasource:
    driverClassName: org.mariadb.jdbc.Driver
    url: jdbc:mariadb://localhost:3306/SOC_Dashboard
    username: admin
    password: password
    timeBetweenEvictionRunsMillis: 1000
    testWhileIdle: true
    validationQuery: SELECT 1

in which I configured the database connection for my project (I used JdbcTemplate to interact with my databse since now and I am replacing with Spring Data JPA).

I am not so into Spring Boot but it seems to me that exist 2 ways to set the configuration into my application.properties file: one is as done in my configuration (using something like a tree structure) and another one use a "flast" structure.

Searching online I only found this "flat" configuration for JPA:

spring.jpa.hibernate.ddl-auto=none

that is not working in my case. Putting it into my application.properties file I obtain a syntax error due to the fact that it is using the other tree style.

So I am trying to change my original file in this way:

spring:
  application:
    name: Spring Boot Excel API
  datasource:
    driverClassName: org.mariadb.jdbc.Driver
    url: jdbc:mariadb://localhost:3306/SOC_Dashboard
    username: admin
    password: password
    timeBetweenEvictionRunsMillis: 1000
    testWhileIdle: true
    validationQuery: SELECT 1

  jpa:
    hibernate: 
      ddl-auto: none

Is it the right way to proceed?

Another doubt is related to the ddl-auto configuration. My development is database driven. I design the DB tables and JPA entity have to map these tables. I don't want to create\modify tables starting from my entity. Is it the right configuration?

AndreaNobili
  • 40,955
  • 107
  • 324
  • 596
  • 1
    that appears to be the yaml file structure. [reference](https://docs.spring.io/spring-boot/docs/current/reference/html/spring-boot-features.html#boot-features-external-config-yaml). Shouldn't the file be named application.yml ? – R.G Mar 22 '20 at 14:04
  • Please refer this [documentation](https://docs.spring.io/autorepo/docs/spring-boot/current/reference/htmlsingle/#howto-database-initialization) for your second query.`spring.jpa.hibernate.ddl-auto=none` is the configuration and yours looks correct – R.G Mar 22 '20 at 14:11

1 Answers1

0

To answer your first question, YES. It is the right way of configuring spring.jpa.hibernate.ddl-auto configuration in YAML files. And the properties file which you've mention in YAML format. So, the file name should be application.yml. In spring boot, spring-boot-starter-web dependency will automatically include snakeyaml dependency to read YAML files.

For the second question, you can mention none for ddl-auto if you don't want to create tables automatically or you can simply avoid the configuration. Please refer : How does spring.jpa.hibernate.ddl-auto property exactly work in Spring?

Sulthan
  • 354
  • 3
  • 19