fix: @Query with projection and List<List> for Data JPA#1823
fix: @Query with projection and List<List> for Data JPA#1823
Conversation
|
@radovanradic Can you please investigate the problem? |
I will |
316d6c7 to
bd33ddc
Compare
|
Kudos, SonarCloud Quality Gate passed!
|
| import java.util.List; | ||
| @Repository | ||
| public interface MicronautTaskRepository extends CrudRepository<MicronautTask, Long> { | ||
| @Query("select count(*), year(t.dueDate) from MicronautTask t group by year(t.dueDate)") |
There was a problem hiding this comment.
This works when written as
@Query("select count(*) as number, year(t.dueDate) as year from MicronautTask t group by year(t.dueDate)")
because of this line of our code in AbstractHibernateRepository
Set<String> properties = tuple.getElements().stream().map(TupleElement::getAlias).collect(Collectors.toCollection(() -> new TreeSet<>(String.CASE_INSENSITIVE_ORDER)));
expects that TupleElement::getAlias is not null and is one of properties Set which is number, year in our case. Then query can be executed.
| Iterable<TasksPerYear> countByDueYear(); | ||
|
|
||
| @Query("select count(*), year(t.dueDate) from MicronautTask t group by year(t.dueDate)") | ||
| List<List<Integer>> countByDueYearReturnList(); |
There was a problem hiding this comment.
And this fails with the error
Cannot create TypedQuery for query with more than one return using requested result type [java.util.List]
I tried to change it to List<Object[]> which I know Hibernate can return but does not work in our code and we probably can't support it now without some refactoring.








This PR contains two failing tests annotated with
@PendingFeature.Given these Entities with a
ManyToOneRelationshipand:
Both methods in this repository fail:
TasksPerYearis a POJO:I expected both to pass.