3434import jakarta .persistence .TypedQuery ;
3535import jakarta .persistence .criteria .CriteriaBuilder ;
3636import jakarta .persistence .criteria .CriteriaQuery ;
37- import jakarta .persistence .criteria .Order ;
3837import jakarta .persistence .criteria .ParameterExpression ;
3938import jakarta .persistence .criteria .Path ;
4039import jakarta .persistence .criteria .Predicate ;
@@ -212,13 +211,13 @@ public void deleteAllByIdInBatch(Iterable<ID> ids) {
212211 }
213212
214213 if (entityInformation .hasCompositeId ()) {
215- // XXX Hibernate just creates an empty Entity when doing the getById.
216- // Others might do a select right away causing a big performance penalty.
217- // See JavaDoc for getById.
214+
218215 List <T > entities = new ArrayList <>();
219- ids .forEach (id -> entities .add (getById (id )));
216+ // generate entity (proxies) without accessing the database.
217+ ids .forEach (id -> entities .add (getReferenceById (id )));
220218 deleteAllInBatch (entities );
221219 } else {
220+
222221 String queryString = String .format (DELETE_ALL_QUERY_BY_ID_STRING , entityInformation .getEntityName (),
223222 entityInformation .getIdAttribute ().getName ());
224223
@@ -292,7 +291,6 @@ public Optional<T> findById(ID id) {
292291 * Returns {@link QueryHints} with the query hints based on the current {@link CrudMethodMetadata} and potential
293292 * {@link EntityGraph} information.
294293 *
295- * @return
296294 */
297295 protected QueryHints getQueryHints () {
298296 return metadata == null ? NoHints .INSTANCE : DefaultQueryHints .of (entityInformation , metadata );
@@ -377,7 +375,7 @@ public List<T> findAllById(Iterable<ID> ids) {
377375
378376 if (entityInformation .hasCompositeId ()) {
379377
380- List <T > results = new ArrayList <T >();
378+ List <T > results = new ArrayList <>();
381379
382380 for (ID id : ids ) {
383381 findById (id ).ifPresent (results ::add );
@@ -388,7 +386,7 @@ public List<T> findAllById(Iterable<ID> ids) {
388386
389387 Collection <ID > idCollection = Streamable .of (ids ).toList ();
390388
391- ByIdsSpecification <T > specification = new ByIdsSpecification <T >(entityInformation );
389+ ByIdsSpecification <T > specification = new ByIdsSpecification <>(entityInformation );
392390 TypedQuery <T > query = getQuery (specification , Sort .unsorted ());
393391
394392 return query .setParameter (specification .parameter , idCollection ).getResultList ();
@@ -403,7 +401,7 @@ public List<T> findAll(Sort sort) {
403401 public Page <T > findAll (Pageable pageable ) {
404402
405403 if (isUnpaged (pageable )) {
406- return new PageImpl <T >(findAll ());
404+ return new PageImpl <>(findAll ());
407405 }
408406
409407 return findAll ((Specification <T >) null , pageable );
@@ -428,7 +426,7 @@ public List<T> findAll(@Nullable Specification<T> spec) {
428426 public Page <T > findAll (@ Nullable Specification <T > spec , Pageable pageable ) {
429427
430428 TypedQuery <T > query = getQuery (spec , pageable );
431- return isUnpaged (pageable ) ? new PageImpl <T >(query .getResultList ())
429+ return isUnpaged (pageable ) ? new PageImpl <>(query .getResultList ())
432430 : readPage (query , getDomainClass (), pageable , spec );
433431 }
434432
@@ -442,7 +440,7 @@ public <S extends T> Optional<S> findOne(Example<S> example) {
442440
443441 try {
444442 return Optional
445- .of (getQuery (new ExampleSpecification <S >(example , escapeCharacter ), example .getProbeType (), Sort .unsorted ())
443+ .of (getQuery (new ExampleSpecification <>(example , escapeCharacter ), example .getProbeType (), Sort .unsorted ())
446444 .getSingleResult ());
447445 } catch (NoResultException e ) {
448446 return Optional .empty ();
@@ -452,7 +450,7 @@ public <S extends T> Optional<S> findOne(Example<S> example) {
452450 @ Override
453451 public <S extends T > long count (Example <S > example ) {
454452 return executeCountQuery (
455- getCountQuery (new ExampleSpecification <S >(example , escapeCharacter ), example .getProbeType ()));
453+ getCountQuery (new ExampleSpecification <>(example , escapeCharacter ), example .getProbeType ()));
456454 }
457455
458456 @ Override
@@ -468,13 +466,13 @@ public <S extends T> boolean exists(Example<S> example) {
468466
469467 @ Override
470468 public <S extends T > List <S > findAll (Example <S > example ) {
471- return getQuery (new ExampleSpecification <S >(example , escapeCharacter ), example .getProbeType (), Sort .unsorted ())
469+ return getQuery (new ExampleSpecification <>(example , escapeCharacter ), example .getProbeType (), Sort .unsorted ())
472470 .getResultList ();
473471 }
474472
475473 @ Override
476474 public <S extends T > List <S > findAll (Example <S > example , Sort sort ) {
477- return getQuery (new ExampleSpecification <S >(example , escapeCharacter ), example .getProbeType (), sort )
475+ return getQuery (new ExampleSpecification <>(example , escapeCharacter ), example .getProbeType (), sort )
478476 .getResultList ();
479477 }
480478
@@ -548,7 +546,7 @@ public <S extends T> List<S> saveAll(Iterable<S> entities) {
548546
549547 Assert .notNull (entities , "Entities must not be null!" );
550548
551- List <S > result = new ArrayList <S >();
549+ List <S > result = new ArrayList <>();
552550
553551 for (S entity : entities ) {
554552 result .add (save (entity ));
@@ -580,7 +578,6 @@ public void flush() {
580578 * @param query must not be {@literal null}.
581579 * @param spec can be {@literal null}.
582580 * @param pageable must not be {@literal null}.
583- * @return
584581 * @deprecated use {@link #readPage(TypedQuery, Class, Pageable, Specification)} instead
585582 */
586583 @ Deprecated
@@ -596,7 +593,6 @@ protected Page<T> readPage(TypedQuery<T> query, Pageable pageable, @Nullable Spe
596593 * @param domainClass must not be {@literal null}.
597594 * @param spec can be {@literal null}.
598595 * @param pageable can be {@literal null}.
599- * @return
600596 */
601597 protected <S extends T > Page <S > readPage (TypedQuery <S > query , final Class <S > domainClass , Pageable pageable ,
602598 @ Nullable Specification <S > spec ) {
@@ -615,7 +611,6 @@ protected <S extends T> Page<S> readPage(TypedQuery<S> query, final Class<S> dom
615611 *
616612 * @param spec can be {@literal null}.
617613 * @param pageable must not be {@literal null}.
618- * @return
619614 */
620615 protected TypedQuery <T > getQuery (@ Nullable Specification <T > spec , Pageable pageable ) {
621616
@@ -629,7 +624,6 @@ protected TypedQuery<T> getQuery(@Nullable Specification<T> spec, Pageable pagea
629624 * @param spec can be {@literal null}.
630625 * @param domainClass must not be {@literal null}.
631626 * @param pageable must not be {@literal null}.
632- * @return
633627 */
634628 protected <S extends T > TypedQuery <S > getQuery (@ Nullable Specification <S > spec , Class <S > domainClass ,
635629 Pageable pageable ) {
@@ -643,7 +637,6 @@ protected <S extends T> TypedQuery<S> getQuery(@Nullable Specification<S> spec,
643637 *
644638 * @param spec can be {@literal null}.
645639 * @param sort must not be {@literal null}.
646- * @return
647640 */
648641 protected TypedQuery <T > getQuery (@ Nullable Specification <T > spec , Sort sort ) {
649642 return getQuery (spec , getDomainClass (), sort );
@@ -655,7 +648,6 @@ protected TypedQuery<T> getQuery(@Nullable Specification<T> spec, Sort sort) {
655648 * @param spec can be {@literal null}.
656649 * @param domainClass must not be {@literal null}.
657650 * @param sort must not be {@literal null}.
658- * @return
659651 */
660652 protected <S extends T > TypedQuery <S > getQuery (@ Nullable Specification <S > spec , Class <S > domainClass , Sort sort ) {
661653
@@ -676,7 +668,6 @@ protected <S extends T> TypedQuery<S> getQuery(@Nullable Specification<S> spec,
676668 * Creates a new count query for the given {@link Specification}.
677669 *
678670 * @param spec can be {@literal null}.
679- * @return
680671 * @deprecated override {@link #getCountQuery(Specification, Class)} instead
681672 */
682673 @ Deprecated
@@ -689,7 +680,6 @@ protected TypedQuery<Long> getCountQuery(@Nullable Specification<T> spec) {
689680 *
690681 * @param spec can be {@literal null}.
691682 * @param domainClass must not be {@literal null}.
692- * @return
693683 */
694684 protected <S extends T > TypedQuery <Long > getCountQuery (@ Nullable Specification <S > spec , Class <S > domainClass ) {
695685
@@ -705,7 +695,7 @@ protected <S extends T> TypedQuery<Long> getCountQuery(@Nullable Specification<S
705695 }
706696
707697 // Remove all Orders the Specifications might have applied
708- query .orderBy (Collections .< Order > emptyList ());
698+ query .orderBy (Collections .emptyList ());
709699
710700 return em .createQuery (query );
711701 }
@@ -716,7 +706,6 @@ protected <S extends T> TypedQuery<Long> getCountQuery(@Nullable Specification<S
716706 * @param spec can be {@literal null}.
717707 * @param domainClass must not be {@literal null}.
718708 * @param query must not be {@literal null}.
719- * @return
720709 */
721710 private <S , U extends T > Root <U > applySpecificationToCriteria (@ Nullable Specification <U > spec , Class <U > domainClass ,
722711 CriteriaQuery <S > query ) {
@@ -762,7 +751,6 @@ private void applyQueryHints(Query query) {
762751 * Executes a count query and transparently sums up all values returned.
763752 *
764753 * @param query must not be {@literal null}.
765- * @return
766754 */
767755 private static long executeCountQuery (TypedQuery <Long > query ) {
768756
@@ -830,8 +818,8 @@ private static class ExampleSpecification<T> implements Specification<T> {
830818 /**
831819 * Creates new {@link ExampleSpecification}.
832820 *
833- * @param example
834- * @param escapeCharacter
821+ * @param example the example to base the specification of. Must not be {@literal null}.
822+ * @param escapeCharacter the escape character to use for like expressions. Must not be {@literal null}.
835823 */
836824 ExampleSpecification (Example <T > example , EscapeCharacter escapeCharacter ) {
837825
0 commit comments