44
44
import org .springframework .data .domain .PageImpl ;
45
45
import org .springframework .data .domain .Pageable ;
46
46
import org .springframework .data .domain .Sort ;
47
+ import org .springframework .data .domain .TypedExampleSpec ;
47
48
import org .springframework .data .jpa .convert .QueryByExamplePredicateBuilder ;
48
49
import org .springframework .data .jpa .domain .Specification ;
49
50
import org .springframework .data .jpa .provider .PersistenceProvider ;
@@ -437,7 +438,7 @@ public List<T> findAll(Specification<T> spec, Sort sort) {
437
438
@ Override
438
439
public <S extends T > S findOne (Example <S > example ) {
439
440
try {
440
- return getQuery (new ExampleSpecification <S >(example ), example . getResultType (), (Sort ) null ).getSingleResult ();
441
+ return getQuery (new ExampleSpecification <S >(example ), getResultType (example ), (Sort ) null ).getSingleResult ();
441
442
} catch (NoResultException e ) {
442
443
return null ;
443
444
}
@@ -449,15 +450,15 @@ public <S extends T> S findOne(Example<S> example) {
449
450
@ SuppressWarnings ("unchecked" )
450
451
@ Override
451
452
public <S extends T > long count (Example <S > example ) {
452
- return executeCountQuery (getCountQuery (new ExampleSpecification <S >(example ), example . getResultType ()));
453
+ return executeCountQuery (getCountQuery (new ExampleSpecification <S >(example ), getResultType (example )));
453
454
}
454
455
455
456
/* (non-Javadoc)
456
457
* @see org.springframework.data.repository.query.QueryByExampleExecutor#exists(org.springframework.data.domain.Example)
457
458
*/
458
459
@ Override
459
460
public <S extends T > boolean exists (Example <S > example ) {
460
- return !getQuery (new ExampleSpecification <S >(example ), example . getResultType (), (Sort ) null ).getResultList ()
461
+ return !getQuery (new ExampleSpecification <S >(example ), getResultType (example ), (Sort ) null ).getResultList ()
461
462
.isEmpty ();
462
463
}
463
464
@@ -467,7 +468,7 @@ public <S extends T> boolean exists(Example<S> example) {
467
468
*/
468
469
@ Override
469
470
public <S extends T > List <S > findAll (Example <S > example ) {
470
- return getQuery (new ExampleSpecification <S >(example ), example . getResultType (), (Sort ) null ).getResultList ();
471
+ return getQuery (new ExampleSpecification <S >(example ), getResultType (example ), (Sort ) null ).getResultList ();
471
472
}
472
473
473
474
/*
@@ -476,7 +477,7 @@ public <S extends T> List<S> findAll(Example<S> example) {
476
477
*/
477
478
@ Override
478
479
public <S extends T > List <S > findAll (Example <S > example , Sort sort ) {
479
- return getQuery (new ExampleSpecification <S >(example ), example . getResultType (), sort ).getResultList ();
480
+ return getQuery (new ExampleSpecification <S >(example ), getResultType (example ), sort ).getResultList ();
480
481
}
481
482
482
483
/*
@@ -487,9 +488,9 @@ public <S extends T> List<S> findAll(Example<S> example, Sort sort) {
487
488
public <S extends T > Page <S > findAll (Example <S > example , Pageable pageable ) {
488
489
489
490
ExampleSpecification <S > spec = new ExampleSpecification <S >(example );
490
- TypedQuery <S > query = getQuery (new ExampleSpecification <S >(example ), example . getResultType (), pageable );
491
+ TypedQuery <S > query = getQuery (new ExampleSpecification <S >(example ), getResultType (example ), pageable );
491
492
return pageable == null ? new PageImpl <S >(query .getResultList ())
492
- : readPage (query , example . getResultType (), pageable , spec );
493
+ : readPage (query , getResultType (example ), pageable , spec );
493
494
}
494
495
495
496
/*
@@ -763,6 +764,15 @@ private void applyQueryHints(Query query) {
763
764
}
764
765
}
765
766
767
+
768
+ private <S extends T > Class <S > getResultType (Example <S > example ) {
769
+
770
+ if (example .getExampleSpec () instanceof TypedExampleSpec <?>){
771
+ return example .getResultType ();
772
+ }
773
+ return (Class <S >) getDomainClass ();
774
+ }
775
+
766
776
/**
767
777
* Executes a count query and transparently sums up all values returned.
768
778
*
0 commit comments