0

I have problem with hibernate.ddl-auto: none in spring. It works fine in development environment and does not execute sql's like drop table. But in production environment same property seems like it's not working. And execute drop and create tables sql's. In application.yaml on production:

spring:
  jpa:
    hibernate.ddl-auto: none

I checked this value in application by this:

@Bean
public CommandLineRunner initProject() {
    return (args) -> {
        logger.info(env.getProperty("spring.jpa.hibernate.ddl-auto")); //this prints "create"

So it looks like some internal code changed it value. I run application by this command:

./mvnw spring-boot:run
3
  • Do you have different spring profiles configured? Commented Apr 8, 2021 at 16:44
  • I have something like this in application.yaml profiles: active: development This was in development, in production I have not. But when I copied this to production application.yaml it doesn't change anything Commented Apr 8, 2021 at 16:51
  • Do you have embeded database in production? Commented Apr 8, 2021 at 17:33

2 Answers 2

4

The value has to come from somewhere...

You can easily trace this if you have actuator enabled

 <dependency>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-starter-actuator</artifactId>
 </dependency>

And expose the env endpoint via

management:
  endpoints:
    web:
      exposure:
        include: env

Then you can visit that endpoint via /actuator/env Here you can even find the location where you have defined the value.

{
  "name": "Config resource 'class path resource [application.yaml]' via location 'optional:classpath:/'",
  "properties": {
  "spring.jpa.hibernate.ddl-auto": {
    "value": "none",
    "origin": "class path resource [application.yaml] - 3:25"
},
  "management.endpoints.web.exposure.include": {
  "value": "env",
  "origin": "class path resource [application.yaml] - 9:18"
}...
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for answet. With this I find out that I have in target folder old file application.properties which overrides data from application.yaml. I though this file will be deleted automatically. For this to work I had to remove folder target
0

The value none is undocumented, use validate instead. See also:What are the possible values of the Hibernate hbm2ddl.auto configuration and what do they do

2 Comments

With validate value it also doesn't change anything. In console it prints "create" and also works like create. That mean it drops all tables and creates it back
So, probably your property is overridden in production mode. Do you have production-specific profile configuration?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.