0

I have a java progam using Maven, JPA, Eclipse, Jenkins. While developing I have the setting

spring: jpa: show-sql: true

in my application.yml file which works fine. Now, for a load test I have huge chunk of data. If I execute the test it works fine in Eclipse, but fails in Maven as the SureFire Plugin fails on such large console output. I can make it work by redirecting the console to a file, but that won't work for Jenkins and it won't work if I start the tests altogether because I want to see the result on the console obviously. So I would like to have this setting (show-sql) be switched off temporarily. I suppose it must live somewhere in the JPA / Hibernate configuration classes, but I couldn't find any combination yet that would allow me to change it.

Any advise is appreciated, Stephan

The closest I suppose I came to it was by this:

entityManager.setProperty( "hibernate.show_sql", false );
entityManager.setProperty( "spring.jpa.hibernate.show_sql", false );
entityManager.setProperty( "javax.persistence.hibernate.show_sql", false );

Where the entityManager is autowired to the component. But when reading those properties, the return is some values from a completely different namespace (some timeout values), so I reckon I am in the wrong corner...

  • Use spring to load test properties, which are separated from development/production – XtremeBaumer Jun 25 '19 at 06:16
  • That's actually in place, so in production is no problem at all. But in test I have quite a large test with many similar requests to check for the complete queue and receive a guess for the performance. So in general I need the output, but for that test I don't. Or at least not after the first few queries because then I see the system in the log. – Stephan Wöbbeking Jun 26 '19 at 11:57

1 Answers1

1

I assume you are also using spring, what you can do is using profiles which is available since version 3. See this link for more information: Spring Profiles. You can active profiles during runtime. For example in application-loadtest.yml would then be your configuration for your loadtests.

Or as alternative you can add this properties as parameter environment variables or as command line argument: Externalized configuration

I hope this helps.

regards, WiPu

WiPU
  • 443
  • 2
  • 9
  • So as a conclusion I understand it is just really not possible to change these settings during runtime / between start and stop of the Spring boot container? Well, if its not possible I see that I should consider alternatives and then I would probably prefer using the profiles as you mentioned which I have used shallowly before. – Stephan Wöbbeking Jun 26 '19 at 12:00
  • What could work, but i haven't tried this myself, is to rebuild the entity manager at some point with the new properties: https://stackoverflow.com/questions/27998502/java-spring-recreate-specific-bean. So you can run some tests and then rebuild the entity manager with enabled/disabled sql log. – WiPU Jun 27 '19 at 07:48
  • Well, yeah about that was exactly my idea as outlined in the initial post more or less. But then I don't have the correct properties path. I have been reading out the entityManager to check what's in there - collecting information is not a bad thing more often than not. But then I found completely different values, the once I set in the application.yml (and want to change by code) are not there so I suppose its not the right corner to manipulate them, is it? – Stephan Wöbbeking Jun 28 '19 at 08:43
  • At least I don't have an idea what properties paths to use... Found no proper documentation to use. If found this: "https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#common-application-properties" but it didn't really got me there... – Stephan Wöbbeking Jun 28 '19 at 08:45
  • i quickly checked it in a project where i can enable / disable the show_sql. What i found is that in this project (spring boot 2.X/ hibernate 5.X) the `LocalContainerEntityManagerFactoryBean` has the jpaPropertyMap hibernate.show_sql=true. This bean builds a `EntityManagerFactory` (implementation from hibernate: `SessionFactoryImpl`) with those properties. – WiPU Jun 28 '19 at 14:20
  • As alternative you can look into something like this: https://vladmihalcea.com/the-best-way-to-log-jdbc-statements/. There the enabled / disable could be easier to achive. Or just disable the hibernate logger respectivly change the loglevel during runtime which might be the simplest solution. – WiPU Jun 28 '19 at 14:23