Skip to content

Using @DocumentReference throws ConverterNotFoundException during constructor creation #3806

Closed
@oooplz

Description

@oooplz
version: spring-data-mongodb-3.3.0-M2

There is demo code below.

@Document
data class User(
    @Id
    var id: ObjectId? = null,
    var username: String,
)

@Document
data class Post(
    @Id
    var id: ObjectId? = null,
    var title: String,
    var content: String?,
    @DocumentReference
    var author: User? = null
)

val user = mongoTemplate.save(User(null, "username0"))
val post = mongoTemplate.save(Post(null, "title0", "content0", user))

mongoTemplate.findById<Post>(post.id!!)
Exceptions is in here.

No converter found capable of converting from type [org.bson.types.ObjectId] to type [com.demo.User]
org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [org.bson.types.ObjectId] to type [com.demo.User]

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions