1

I am facing a "problem" with mongo reactive repositories. I am trying to use kotlin's coroutines and instead of writing fun declaration like this:

fun findEntityById(id: String) : Mono<Entity>

I wrote a suspend function like this :

suspend fun findEntityById(id: String) : Entity

But when I test the function with an id that does not exist, instead of getting an DataAccessException(what I anticipated), I am getting null. Is there a way to "fix" this or get around. For now I only thought of something like this

suspend fun findEntityById(id: String) : Entity = findEntityById(id).awaitSingleOrNull() ?: throw EmptyResultDataAccessException()

Maybe there is a better solution and someone has faced the same "problem" that I have(or maybe I am doing something wrong), i'd be glad to hear any suggestions.

Barracuda
  • 477
  • 5
  • 19
  • Can you file a bug report in https://github.com/spring-projects/spring-data-commons/? – mp911de Nov 15 '21 at 08:48
  • 1
    @mp911de, you mean make an issue on git? – Barracuda Nov 15 '21 at 17:39
  • It seems it doesn't work this way. You have to use Mono and then call one of await methods. –  Nov 24 '21 at 09:48
  • @breedish, it does work this way( Throws EmptyResultDataAccessException) when used with r2dbc. This problem occurred to me when I used mongo reactive repositories. – Barracuda Nov 24 '21 at 10:32

0 Answers0