question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support direct DTO mapping for repository query methods

See original GitHub issue

Hi,

I am writing a custom query but as I am not able to cast the expression to some custom objects. In JPA you can do write custom queries like

@Query("SELECT new com.baeldung.aggregation.model.custom.CommentCount(c.year, COUNT(c.year)) "
  + "FROM Comment AS c GROUP BY c.year ORDER BY c.year DESC")
List<CommentCount> countTotalCommentsByYearClass(); 

But with ReactiveCassandraRepository I am getting errors org.springframework.data.cassandra.CassandraQuerySyntaxException:

How can I cast to custom object in ReactiveCassandraRepository?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
mp911decommented, Jul 1, 2021

We currently do not have the means to map results through query methods onto DTO’s directly as we always need to consider the underlying entity in terms of column and type mapping. That is a general issue we have with all Spring Data modules and we plan to do something about it in general. For the time being, please use the CassandraTemplate directly to run aggregation queries without intermediate entity mapping.

0reactions
Zaky7commented, Jun 30, 2021

as soon as I add maxSalary and minSalary in my Users class, it is working fine. is any better way of doing this??

Read more comments on GitHub >

github_iconTop Results From Across the Web

Spring Data JPA - How to Return DTOs from Native Queries
Spring Data JPA doesn't provide an automatic mapping of class-based DTOs for native queries. The easiest way to use this projection is to...
Read more >
How to map sql native query result into DTO in spring jpa ...
You can define the following named native query with appropriate sql result set mapping: import javax.persistence.
Read more >
Spring Data JPA – How to Return DTOs from Native Queries
When using Spring Data JPA, you are used to derived and custom queries that return the result in your preferred format.
Read more >
How to map Custom Query Results into DTO in Spring Data JPA
Introduction In this tutorial I will show you how to map custom query results into DTO in Spring Data JPA. Situations may occur...
Read more >
The best way to map a projection query to a DTO (Data ...
Learn the best way to map a DTO projection when using JPA and Hibernate using constructor expression, Tuple, SqlResultSetMapping, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found