-
Notifications
You must be signed in to change notification settings - Fork 29
Setting up query counter with Spring Boot #14
Comments
Yes, that's not enough. You also need to wrap the Anyway, I'm going to close this issue since it is Spring Boot responsibility to add support for other libraries, not the other way around. |
Thanks for the very quick answer. I've read that article multiple times and the following line led me to believe that all you needed was to add the maven dependency to set up the interceptor:
In any event there was no indication of what else I could do, so I thought that the technique I describe could be useful for other users. |
I can't add the dependency to the project. What if someone wants to use it with Java EE? This is like adding a Spring dependency into Log4J. |
I agree and I'm not asking for you to do that, just documenting my experience to help other users that may find themselves in the same position (which I imagine is a common one, since it's provided by a bunch of popular gems in Rails and core Django functionality since 2011; and we haven't been having any less N+1 problems with JPA/Hibernate than I've had with other ORM's, even after I read your excellent book on the subject). Anyway, no action asked from you. Feel free to document this or let Google take care of it. Thanks again for your work, if there were just a few others like you around, life in the Java/Spring ecosystem would be much less painful. |
I think it's better if you send me a Pull Request with the README.md file updated with this info for Spring Boot. |
Hi Vlad,
TL;DR To make this work with Spring Boot I had to add as a dependency the library
https://github.com/gavlyukovskiy/spring-boot-data-source-decorator
and add the propertydecorator.datasource.datasource-proxy.count-query=true
to application.properties.First let me thank you for your fantastic work. Coming to Java/Spring Boot from other platforms has not been a pleasant experience due to the lack of community resources and your contribution is a shining exception.
My latest challenge has been into finding the equivalent functionality to Django's assertNumQueries for testing, since we have been finding hard to keep the Hibernate N+1 situation under control. Your library fills the bill.
However, It was challenging to make it work on our Spring Boot 2 configuration, so I'd like to contribute with the (certainly clumsy) solution I eventually found, and have your opinion if there's a better one.
Just adding the db-util dependency to the pom.xml and calling
SQLStatementCountValidator
s.reset()
and.assertSelectCount()
was not enough. The counter was not incrementing. I am using the@Transactional
and@SpringBootTest
annotations in the test class. After much fiddling I ended up coming up with a solution:spring-boot-data-source
in the pom.xml:decorator.datasource.datasource-proxy.count-query=true
to application.properties.Thanks
The text was updated successfully, but these errors were encountered: