1

I have tried setting the log level of the Spring Boot application (via application.yml) to error.

logging:
  level:
    root: error
spring:
  jpa:
    show-sql: false
    hibernate:
      ddl-auto: update

However, I still see the hibernate generated queries being printed to stdout, example:

Hibernate: alter table mytable add column name varchar(255)

Is there anyway to disable this? I have tried the Hibernate log levels as well.

Thanks

Kenneth Clark
  • 356
  • 1
  • 14
  • Can you provide a minimum reproducible for it? Like `pom.xml`, `application.yml` and other logger configurations you have (for ex `logback`). – Lucas Campos May 23 '20 at 17:04
  • This isn't an error, simply run the Axon Framework in Spring Boot and it will output to the console. I am looking for a way to switch off the Hibernate logging. Apologies for my ignorance but I can't think of any other way to explain it. – Kenneth Clark May 24 '20 at 18:12
  • Potentially this is a duplicate of this issue? https://stackoverflow.com/questions/36496178/cant-avoid-hibernate-logging-sql-to-console-with-spring-boot-and-logback – Steven May 25 '20 at 13:56
  • Thanks Steven, I ran through all the potential configurations in that thread and came up empty. Is there not a flag being set in the auto configuration classes of the axon jpa setup? If you guys aren't doing it explicitly your side then it must be something on my side that I am missing. – Kenneth Clark May 26 '20 at 15:57
  • That's bothersome, hope that would provide a hook for you to look at. Any how, Axon's auto configuration with JPA can be found in these two files: - https://github.com/AxonFramework/AxonFramework/blob/master/spring-boot-autoconfigure/src/main/java/org/axonframework/springboot/autoconfig/JpaAutoConfiguration.java - https://github.com/AxonFramework/AxonFramework/blob/master/spring-boot-autoconfigure/src/main/java/org/axonframework/springboot/autoconfig/JpaEventStoreAutoConfiguration.java – Steven May 27 '20 at 09:28
  • As I believe you are using Axon Server, the second auto config isn't even taken into account. The former in turn just creates Axon beans, without bothering with Hibernate directly. – Steven May 27 '20 at 09:29
  • Thanks Steven, I am not using the Axon Server. Thanks so much for your time trying to help with this. I will dig around the Spring JPA and try figure out what I am missing. If I come up with anything I will post it here for future reference. Thanks again. I will remove the Axon ref as it is not coming from the framework. – Kenneth Clark May 28 '20 at 09:26

1 Answers1

0

The only way I managed to get this to stop spitting out SQL was to add the property at a code level.

private Properties additionalProperties(){
    var properties = new Properties();
    properties.setProperty("hibernate.show_sql", "false");
    properties.setProperty("hibernate.dialect", "org.hibernate.dialect.PostgreSQLDialect");
    return properties;
}

The portion containing the dialect was already there and I added the show_sql - I am not sure why the properties file was not doing this, perhaps

em.setJpaProperties(additionalProperties());

is overriding the properties set in the application properties file (which makes sense as it is a "set" call). Upon attempting to move the these values to the properties file and stop setting them in the config file the properties still weren't being set.

I am leaving this here as an explanation for anyone else that might have gone down the same rabbit hole as myself - should I make further progress on setting the values in the properties file I will share it here as well.

Thanks to everyone that reviewed this questions and those that tried to help

Kenneth Clark
  • 356
  • 1
  • 14