Skip to content
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

No accessor to set property @org.springframework.data.annotation.Id() [DATAMONGO-2125] #2993

Closed
spring-projects-issues opened this issue Nov 1, 2018 · 3 comments
Assignees
Labels
in: core Issues in core support in: repository Repositories abstraction status: declined A suggestion or change that we don't feel we should currently apply type: bug A general bug

Comments

@spring-projects-issues
Copy link

Ebram Sherif opened DATAMONGO-2125 and commented

So I am using spring boot parent starter 2.1.0 and I have some model like this written in kotlinn

// open class Person(
@Id
val id: String? = null,
val name: String
)

then I try to insert it using

personRepo.insert(Person("mike"))

it does actually insert the object into the DB but I get a runtime error 

 

// Caused by: java.lang.UnsupportedOperationException: No accessor to set property @org.springframework.data.annotation.Id()private final java.lang.String com.person.id!Caused by: java.lang.UnsupportedOperationException: No accessor to set property @org.springframework.data.annotation.Id()private final java.lang.String com.person.id! at com.person_Accessor_sjnbwf.setProperty(Unknown Source) at org.springframework.data.mapping.model.ConvertingPropertyAccessor.setProperty(ConvertingPropertyAccessor.java:61) at org.springframework.data.mongodb.core.EntityOperations$AdaptibleMappedEntity.populateIdIfNecessary(EntityOperations.java:605) at org.springframework.data.mongodb.core.MongoTemplate.populateIdIfNecessary(MongoTemplate.java:2569) at org.springframework.data.mongodb.core.MongoTemplate.doInsert(MongoTemplate.java:1219) at org.springframework.data.mongodb.core.MongoTemplate.insert(MongoTemplate.java:1150) at org.springframework.data.mongodb.repository.support.SimpleMongoRepository.insert(SimpleMongoRepository.java:244) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.springframework.data.repository.core.support.RepositoryComposition$RepositoryFragments.invoke(RepositoryComposition.java:359) at org.springframework.data.repository.core.support.RepositoryComposition.invoke(RepositoryComposition.java:200) at org.springframework.data.repository.core.support.RepositoryFactorySupport$ImplementationMethodExecutionInterceptor.invoke(RepositoryFactorySupport.java:644) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:608) at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.lambda$invoke$3(RepositoryFactorySupport.java:595) at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:595) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:59) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:93) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) at org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:61) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) at org.springframework.data.repository.core.support.MethodInvocationValidator.invoke(MethodInvocationValidator.java:99) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212) 

I was using 2.0.6 for spring boot parent starter and it was returning the object normally but just by updating the POM to 2.1.0 now im facing this


Affects: 2.1.2 (Lovelace SR2)

Issue Links:

  • DATAMONGO-2134 UnsupportedOperationException: No accessor to set property when using immutable entity
    ("is duplicated by")
@spring-projects-issues
Copy link
Author

Mark Paluch commented

This is the intended behavior. With Spring Data 2.1 we introduced support for immutable objects and we no longer update final fields. Previously, we updated fields reflectively/through MethodHandles without regard to whether fields were final or non-final.

Your Kotlin class is a regular open class, however fields are final as they are declared with val and not var. We support Kotlin data classes with immutable fields as we're using the copy(…) method to create updated object instances

@spring-projects-issues spring-projects-issues added type: bug A general bug status: declined A suggestion or change that we don't feel we should currently apply in: repository Repositories abstraction in: core Issues in core support labels Dec 30, 2020
@murilonerdx
Copy link

I'm using kotlin, and my tests failed, but I just put a var in the id and it worked

@document
class DistributionEngine(
@id
var id: String? = null,
...
}

@stephmafole
Copy link

Just add jackson dependency in your build.gradle : com.fasterxml.jackson.module:jackson-module-kotlin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core support in: repository Repositories abstraction status: declined A suggestion or change that we don't feel we should currently apply type: bug A general bug
Projects
None yet
Development

No branches or pull requests

4 participants