Skip to content

"Required identifier property not found" in Kotlin #3685

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
shanedonburke opened this issue Jun 24, 2021 · 5 comments
Closed

"Required identifier property not found" in Kotlin #3685

shanedonburke opened this issue Jun 24, 2021 · 5 comments
Assignees

Comments

@shanedonburke
Copy link

Hi,

I have a Kotlin project with spring-boot-starter-data-mongodb-reactive. My sealed class Question has a collection. Inserting and deleting work fine, but using my method for updating a document results in this:

"timestamp": 1624474446743,
    "path": "/api/questions/60d3834eef43b774dbb458d5",
    "status": 500,
    "error": "Internal Server Error",
    "message": "Required identifier property not found for class com.sdbtechnology.surveytool.assessment.Question!",
    "requestId": "b8726976-6",
    "trace": "java.lang.IllegalStateException: Required identifier property not found for class com.sdbtechnology.surveytool.assessment.Question!

Question.kt looks like this:

@JsonIgnoreProperties(ignoreUnknown = true)
@Document(collection = QuestionRepository.COLLECTION_NAME)
sealed class Question : Scorable {
  abstract var id: String?
  // ...
  @Document(collection = QuestionRepository.COLLECTION_NAME)
  data class Text(
    override var id: String? = null,
    override val name: String? = null,
    override val tags: MutableSet<String>? = null,
    override val bodyComponents: List<BodyContent>,
    override val required: Boolean,
    val pattern: String? = null,
    val tag: TextQuestionTag = TextQuestionTag.NONE,
    override val correctTextAnswers: List<String>? = null
  ) : Question(), SimpleTextBased {
      // ...

I'm updating the document with this code:

open class BaseRepositoryImpl<T : Any, ID : Serializable>(
    private val entityInformation: MongoEntityInformation<T, ID>,
    private val mongoOperations: ReactiveMongoOperations
) : SimpleReactiveMongoRepository<T, ID>(entityInformation, mongoOperations), BaseRepository<T, ID> {
    override fun <S : T> update(entity: S): Mono<S> {
        val id = entityInformation.idAttribute
        val entityId = entityInformation.getRequiredId(entity)
        return mongoOperations.findAndReplace(
            Query(where(id).isEqualTo(entityId)),
            entity,
            options().returnNew(),
            entityInformation.collectionName
        ).switchIfEmpty(
            Mono.error(RuntimeException("Entity [${entityInformation.javaType.name} $entityId] not found"))
        )
    }
}

Specifically, the call to entityInformation.idAttribute is failing. It works fine for my other (non-abstract) document class.

I've tried the following things:

  1. Making sure id isn't null
  2. Annotating id with @Id in both Question and Text
  3. Doing the same with @MongoId
  4. Making id not abstract
  5. Changing the type of id to ObjectId instead of String

Is there anything obviously wrong here? Thanks

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jun 24, 2021
@christophstrobl
Copy link
Member

Thanks for reporting. Which version of data-mongodb are you using?
We've seen override cause trouble when trying to resolve properties, so this might be related to spring-projects/spring-data-commons#1911. So you might want to give current main line snapshot builds a try, because the fix for the above mentioned issue has not yet seen a release.
Also a minimal sample (something that we can unzip or git clone, build, and deploy) that reproduces the problem would help us reproduce the problem.

@christophstrobl christophstrobl added status: waiting-for-feedback We need additional information before we can continue and removed status: waiting-for-triage An issue we've not yet triaged labels Jun 25, 2021
@shanedonburke
Copy link
Author

Thanks for the quick response. I'm using 2.2.6.RELEASE.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Jun 25, 2021
@christophstrobl
Copy link
Member

The fix for spring-projects/spring-data-commons#1911 has been released and is available via 3.3.0. Does the issue still exist when using that version?

@christophstrobl christophstrobl added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided labels Jan 19, 2022
@spring-projects-issues
Copy link

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

@spring-projects-issues spring-projects-issues added the status: feedback-reminder We've sent a reminder that we need additional information before we can continue label Jan 26, 2022
@spring-projects-issues
Copy link

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.

@spring-projects-issues spring-projects-issues removed status: waiting-for-feedback We need additional information before we can continue status: feedback-reminder We've sent a reminder that we need additional information before we can continue labels Feb 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants