Hi. I’m trying to create a Post belongsTo User relationship query (the inverse of oneToMany). My user class is :
data class UserDto(
val id: Long?,
...
var posts: List<PostDto>? = emptyList()
)
and my post:
data class PostDto(
val id: Long?,
var userId: Long,
...
var user: UserDto? = null
)
my function was going to be this:
suspend fun findByIdWithUser(id: Long): PostDto? = coroutineScope {
val post = async{findById(id)}
val user = async{userRepository.findById(id)}
return@coroutineScope post.await()?.copy(user = user.await())
}
But it won’t compile because I get this error:
Relying upon circular references is discouraged and they are prohibited by default. Update your application to remove the dependency cycle between beans. As a last resort, it may be possible to break the cycle automatically by setting spring.main.allow-circular-references to true.
Ideas anyone ?