@@ -279,12 +279,8 @@ private Query restrictMaxResultsIfNecessary(Query query, @Nullable ScrollPositio
279279
280280 protected JpqlQueryCreator createCreator (Sort sort , JpaParametersParameterAccessor accessor ) {
281281
282- JpqlQueryCreator jpqlQueryCreator ;
283- synchronized (cache ) {
284- jpqlQueryCreator = cache .get (sort , accessor ); // this caching thingy is broken due to IS NULL rendering for
285- // simple properties
286- }
287-
282+ JpqlQueryCreator jpqlQueryCreator = cache .get (sort , accessor ); // this caching thingy is broken due to IS NULL
283+ // rendering for
288284 if (jpqlQueryCreator != null ) {
289285 return jpqlQueryCreator ;
290286 }
@@ -307,9 +303,7 @@ protected JpqlQueryCreator createCreator(Sort sort, JpaParametersParameterAccess
307303 return creator ;
308304 }
309305
310- synchronized (cache ) {
311- cache .put (sort , accessor , creator );
312- }
306+ cache .put (sort , accessor , creator );
313307
314308 return creator ;
315309 }
@@ -377,13 +371,12 @@ private Sort getDynamicSort(JpaParametersParameterAccessor accessor) {
377371 */
378372 private class CountQueryPreparer extends QueryPreparer {
379373
380- private volatile JpqlQueryCreator cached ;
374+ private final PartTreeQueryCache cache = new PartTreeQueryCache () ;
381375
382376 @ Override
383377 protected JpqlQueryCreator createCreator (Sort sort , JpaParametersParameterAccessor accessor ) {
384378
385- JpqlQueryCreator cached = this .cached ;
386-
379+ JpqlQueryCreator cached = cache .get (Sort .unsorted (), accessor );
387380 if (cached != null ) {
388381 return cached ;
389382 }
@@ -393,7 +386,9 @@ protected JpqlQueryCreator createCreator(Sort sort, JpaParametersParameterAccess
393386 getQueryMethod ().getResultProcessor ().getReturnedType (), provider , templates , em );
394387
395388 if (!accessor .getParameters ().hasDynamicProjection ()) {
396- return this .cached = new CacheableJpqlCountQueryCreator (creator );
389+ cached = new CacheableJpqlCountQueryCreator (creator );
390+ cache .put (Sort .unsorted (), accessor , cached );
391+ return cached ;
397392 }
398393
399394 return creator ;
0 commit comments