0

Basically I have a simple select statement but instead of returning a Mono to the controller, I first want to check if it really returned the String (surname) of this user but instead when trying to get the String it throws an Exception. Code is like this:

@Repository
@Transactional
public interface ApplicationUserRepository extends ReactiveCrudRepository<UsernamePasswordPrinciple, String> {

    @Query("SELECT * FROM USERS where lower(surname) = lower(:surname)")
    Mono<User> findSurename(String surname);

}

@Table("users")
public class User  {

    private String username;
    private String name;
    private String surname;
...
}

I'm using R2DBC (mysql - v.0.9) and Spring Cloud Gateway (v. 2021.0.6) in my project.

Ideally I just want to see there is really a surname in the dabase the same as the user typed. Extracting the surname from the User inside Mono.

I tried using .block() and .subscribe() to basically get the String from the database but it throws an Exception saying it's not allowed.

Is there another way to query database in reactive Spring? An easier way or maybe the ReactiveCrudRepo interface I'm using is not right for this case? Or at least to guarantee this record do exist in database (returning true)

Thanks

  • Please share the code that causes the problem. You are talking about "getting the String" but the code you posted doesn't show anything like that. – Jens Schauder May 08 '23 at 07:34

0 Answers0