You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have the following data class in kotlin, where the "type" attribute always has the fixed value "BILLET", this is because the interface that my class implements asks for this attribute.
I have a record in the mongo database with this information, but when trying to read it I get the following error:
java.lang.UnsupportedOperationException: No accessor to set property private final transient <PACKAGE>.TransactionType <PACKAGE>.BilletTransaction.type
at <PACKAGE>.BilletTransaction_Accessor_wa9qij.setProperty(Unknown Source)
at org.springframework.data.mapping.model.InstantiationAwarePropertyAccessor.setProperty(InstantiationAwarePropertyAccessor.java:81)
at org.springframework.data.mapping.model.ConvertingPropertyAccessor.setProperty(ConvertingPropertyAccessor.java:60)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.readProperties(MappingMongoConverter.java:606)
I noticed that in the class "InstantiationAwarePropertyAccessor" there is a method that tries to use a possible "setter" to configure the value, but it is not possible and the error occurs
Is it possible to get around this error?
The text was updated successfully, but these errors were encountered:
Using Transient annotation this problem is fixed, but the value of field is not saved in the database. In this case, the field is no writable field, is read only
The root of this is that we should refrain from reading immutable properties in the first place. Generally speaking, if the field in your domain model is set to a fixed value, it doesn't make sense to write it to the database.
As MappingMongoConverter is attempting to read a value for an immutable property, we should rather attempt to filter out such properties from being read.
mp911de
transferred this issue from spring-projects/spring-data-commons
Aug 28, 2023
mp911de
changed the title
Problem with kotlin field with fixed value
Support instantiation of Kotlin class with overridden read-only property
Sep 4, 2024
I have the following data class in kotlin, where the "type" attribute always has the fixed value "BILLET", this is because the interface that my class implements asks for this attribute.
I have a record in the mongo database with this information, but when trying to read it I get the following error:
I noticed that in the class "InstantiationAwarePropertyAccessor" there is a method that tries to use a possible "setter" to configure the value, but it is not possible and the error occurs
Is it possible to get around this error?
The text was updated successfully, but these errors were encountered: