Skip to content
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

Sort sort in ReactiveSortingRepository not working in @Query #426

Closed
cheungyatho opened this issue Aug 6, 2020 · 4 comments
Closed

Sort sort in ReactiveSortingRepository not working in @Query #426

cheungyatho opened this issue Aug 6, 2020 · 4 comments
Labels
status: declined A suggestion or change that we don't feel we should currently apply

Comments

@cheungyatho
Copy link

cheungyatho commented Aug 6, 2020

Am I doing something wrong with my code below?
I always got the same result 'asc order' no matter how I change the instance of parameter of fallAll method.
if I remove the statement "@query(value="select r.id from room r")", I got an error " RoomRepository.findAll(org.springframework.data.domain.Sort)! No property findAll found for type Room! " on sever start up
@repository
public interface RoomRepository extends ReactiveSortingRepository<Room, Integer> {

@Override
Flux<Room> findAll();

@Override
@Query(value="select r.id from room r")
Flux<Room> findAll(@SortDefault(sort=Room.TABLE_COLUMN_ID,direction= Sort.Direction.DESC)  Sort sort);

}
@RestController
@RequestMapping("/room")
public class RoomController {

final private RoomRepository roomRepository;

public RoomController(RoomRepository roomRepository) {
    this.roomRepository = roomRepository;
}

@GetMapping("/list")
public Flux<Room> getRoomList() {

    return roomRepository.findAll(Sort.by(Sort.Direction.DESC,Room.TABLE_COLUMN_ID)).log();
}

}

@mp911de mp911de added the status: declined A suggestion or change that we don't feel we should currently apply label Aug 6, 2020
@mp911de
Copy link
Member

mp911de commented Aug 6, 2020

Using Sort with @Query does not work as we would had to analyze and rewrite your query. We don't indent to follow this path as the complexity is hidden in more complex SQL statements where table have aliases or some advanced trickery with joins makes it next to impossible to properly update the desired query.

@mp911de mp911de closed this as completed Aug 6, 2020
@cheungyatho
Copy link
Author

cheungyatho commented Aug 6, 2020

Using Sort with @Query does not work as we would had to analyze and rewrite your query. We don't indent to follow this path as the complexity is hidden in more complex SQL statements where table have aliases or some advanced trickery with joins makes it next to impossible to properly update the desired query.

If this is the case,I should remove the @query annotation.
But if I removed the annotation I would get a warning like

"Failed to create query for method public abstract reactor.core.publisher.Flux org.springframework.data.repository.reactive.ReactiveSortingRepository.findAll(org.springframework.data.domain.Sort)! No property findAll found for type"

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'roomController'

Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'roomRepository'

defined in @EnableR2dbcRepositories declared on R2dbcRepositoriesAutoConfigureRegistrar.EnableR2dbcRepositoriesConfiguration: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract reactor.core.publisher.Flux org.springframework.data.repository.reactive.ReactiveSortingRepository.findAll(org.springframework.data.domain.Sort)! No property findAll found for type Room!

even I did not override the find all method. And make the service shut down. The interface force me to override the method.
What's the proper way to implement the interface?
Do you have any examples for the case?

My model class has the following annotation:
@DaTa
@builder
@NoArgsConstructor
@AllArgsConstructor
@table(Room.TABLE_NAME)
public class Room {
@id
@column(Room.TABLE_COLUMN_ID)
private Integer id;
@column(Room.TABLE_COLUMN_NAME)
private String name;
@column(Room.TABLE_COLUMN_TYPE)
private Integer type;

and the config class :
@configuration
@EnableR2dbcRepositories
public class ApplicationConfiguration {

and my interface for the ReactiveSortingRepository

@repository
public interface RoomRepository extends ReactiveSortingRepository<Room, Integer> {

}

Thanks

@mp911de
Copy link
Member

mp911de commented Aug 6, 2020

Sort support was introduced with a recent change, see #407.

@cheungyatho
Copy link
Author

cheungyatho commented Aug 7, 2020

Sort support was introduced with a recent change, see #407.

    • Thanks for help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: declined A suggestion or change that we don't feel we should currently apply
Projects
None yet
Development

No branches or pull requests

2 participants