-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
This is a cross-post from: https://stackoverflow.com/q/73115112/1097451 with some minor modifications:
This message started popping up after upgrading Spring Data MongoDB a few months ago.
2022-07-25 22:27:33.313 INFO 236203 --- [ main] o.s.d.mongodb.core.convert.QueryMapper : Could not map 'Account.user.favorites'. Maybe a fragment in 'User -> String' is considered a simple type. Mapper continues with user.favorites.
The corresponding minimal working example is:
@Document
class Account(val user: User)
@Document
class User(_favorites: MutableList<String>)
{
@Field("favorites")
private val _favorites: MutableList<String> = _favorites
val favorites: List<String>
get() = _favorites
}
@SpringBootApplication
class DemoApplication(val mongoOperations: MongoOperations): CommandLineRunner
{
override fun run(vararg args: String?)
{
mongoOperations.save(Account(User(mutableListOf("a", "b", "c"))))
mongoOperations.find(
Query.query(where("user.favorites").isEqualTo(listOf("a", "b", "c"))),
Account::class.java)
}
}
fun main(args: Array<String>)
{
runApplication<DemoApplication>(*args)
}
Spring logs this at the INFO
level, so apparently, it does not mean anything wrong, yet the tone indicates that Spring is struggling to understand my code.
Furthermore, the message is logged every time a query is executed — thousands of times.
Note that according to the log message, Spring thinks the types in Account.user.favorites
are User -> String
, but in reality they are User -> List
.
What are the implications of this message? Isn't this supposed to be a WARNING
?
Does my code contain an incorrect type mapping configuration? The reference documentation is not very clear on mapping Kotlin classes.