My project uses Spring Boot 2.1.3, Java 8, QueryDsl 4.2.1. (It is a mature critical project, and upgrading the SB version to the latest 2.4.4 is not feasible at the moment.)
Recently, I have added Spring Data web support to simplify binding request query parameters to the QueryDsl search predicate used in my Spring Data JPA repository methods - with the @QuerydslPredicate
annotation in web controller methods. That, with the ability to customize the bindings for specific properties or whole classes of properties, seemed to work great... Until we discovered that the searches would randomly stop working.
After some investigation, I noticed that sometimes, after the application starts, the customize
method implementation on my Spring Data JPA repository does not get called by the framework prior to the invocation of the controller method that expects the populated predicate. The queries, if they had any search params that rely on customized bindings, would fail. But here's the crazy part. I would stop and restart the application (without changing anything!), and everything would start working, the same query would yield the expected results.
Notably, restarting in the debug mode (in IntelliJ IDEA) would seem to load everything correctly (most of the time but, I think, not always), and the code in the "customize" method would get executed. I would stop and restart the application multiple times without changing anything or rebuilding. Sometimes it would work, and sometimes it would not! The same query/request. The behavior is the same in its inconsistency in different environments. I have ensured that the QueryDSL APT dependency (for annotation processing and code generation for the Q types) is declared with scope provided
and not packed into the JAR.
I see that the Spring QueryDsl library is always included and available on the classpath, which is supposed to ensure the support for the @QuerydslPredicate
annotation to be enabled automatically - per documentation. It seems that - depending on something random at startup - the framework is not finding the customizer implementation for the required domain type (my entity class.)
Once it works, it works. But I can never be sure that it will be enabled once the application is stopped and restarted. Anyone have any idea about what could possibly cause this bizarre behavior? Versions mismatch, perhaps? A bug in Spring Data Web Support for QueryDsl? Should I, perhaps, try using a different, earlier version of spring querydsl to go with my Spring Boot v2.1.3?
In the meantime I have to resort to building the predicates by hand in the service tier, but it would be nice to solve this mystery.