-
Notifications
You must be signed in to change notification settings - Fork 198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: @Query with projection and List<List> for Data JPA #1823
base: 4.7.x
Are you sure you want to change the base?
Conversation
@radovanradic Can you please investigate the problem? |
I will |
316d6c7
to
bd33ddc
Compare
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
ManyToOne
Relationshipand:
Both methods in this repository fail:
TasksPerYear
is a POJO:I expected both to pass.