Spring-data 2.1 get “UnsupportedOperationException: No accessor to set property” with kotlin
Environment:
Spring-boot 2.1.2.RELEASE,
Spring-data 2.1.4.RELEASE,
Kotlin 1.2.x ~ 1.3.x,
Mongodb.
I defined a model class like:
@Document
class MeAccount : Setting() {
lateinit var id: String
val accountEntries = listOf<BankAccount>()
}
When I tried to read this model from mongodb, I got exception stacktrace blow:
java.lang.UnsupportedOperationException: No accessor to set property private final java.util.List com.xxx.MeCustodianAccount.accountEntries!
at com.xxx.MeCustodianAccount_Accessor_fs514j.setProperty(Unknown Source)
at org.springframework.data.mapping.model.ConvertingPropertyAccessor.setProperty(ConvertingPropertyAccessor.java:61)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.readProperties(MappingMongoConverter.java:378)
For attention, the code works fine with spring-boot 1.5.x and spring-data 1.x.
What can I do to solve this issue?
Seems many similar exception reports below:
Spring boot 2.1.0 security change with kotlin data class?
https://github.com/arangodb/spring-data/issues/123
https://github.com/spring-projects/spring-boot/issues/15698
[Resolved] Works after fall back to Spring-boot 2.0.x and spring-data-commons 2.0.x. Will keep 2.1 excluded in future upgrading plans.
mongodb kotlin spring-data spring-data-mongodb
|
show 1 more comment
Environment:
Spring-boot 2.1.2.RELEASE,
Spring-data 2.1.4.RELEASE,
Kotlin 1.2.x ~ 1.3.x,
Mongodb.
I defined a model class like:
@Document
class MeAccount : Setting() {
lateinit var id: String
val accountEntries = listOf<BankAccount>()
}
When I tried to read this model from mongodb, I got exception stacktrace blow:
java.lang.UnsupportedOperationException: No accessor to set property private final java.util.List com.xxx.MeCustodianAccount.accountEntries!
at com.xxx.MeCustodianAccount_Accessor_fs514j.setProperty(Unknown Source)
at org.springframework.data.mapping.model.ConvertingPropertyAccessor.setProperty(ConvertingPropertyAccessor.java:61)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.readProperties(MappingMongoConverter.java:378)
For attention, the code works fine with spring-boot 1.5.x and spring-data 1.x.
What can I do to solve this issue?
Seems many similar exception reports below:
Spring boot 2.1.0 security change with kotlin data class?
https://github.com/arangodb/spring-data/issues/123
https://github.com/spring-projects/spring-boot/issues/15698
[Resolved] Works after fall back to Spring-boot 2.0.x and spring-data-commons 2.0.x. Will keep 2.1 excluded in future upgrading plans.
mongodb kotlin spring-data spring-data-mongodb
2
valproperties don’t have a setter. Change it tovar
– Strelok
Jan 20 at 6:55
@Strelok that is totally unacceptable, val is my admirable feature from kotlin. And the code works with spring-data 1.12.x.
– Jack Zhu
Jan 20 at 6:59
1
Welp, sorry, but that's a fact. Vals in the body need to be initialized in the init block, constructor, or or inline. They don't have a setter
– Zoe
Jan 20 at 17:02
Have you considered making this adataclass and moving the properties into the constructor? As you have it now, nothing (including Spring Data MongoDB) can ever set the value foraccountEntries.
– Mark B
Jan 20 at 17:55
As I said, the 'val' is the most wanted feature of kotlin for us, and the code failed because spring-data 2.1.x breaks the compatiblility. @Mark B The code works totally fine in former spring-data releases.
– Jack Zhu
Jan 21 at 3:50
|
show 1 more comment
Environment:
Spring-boot 2.1.2.RELEASE,
Spring-data 2.1.4.RELEASE,
Kotlin 1.2.x ~ 1.3.x,
Mongodb.
I defined a model class like:
@Document
class MeAccount : Setting() {
lateinit var id: String
val accountEntries = listOf<BankAccount>()
}
When I tried to read this model from mongodb, I got exception stacktrace blow:
java.lang.UnsupportedOperationException: No accessor to set property private final java.util.List com.xxx.MeCustodianAccount.accountEntries!
at com.xxx.MeCustodianAccount_Accessor_fs514j.setProperty(Unknown Source)
at org.springframework.data.mapping.model.ConvertingPropertyAccessor.setProperty(ConvertingPropertyAccessor.java:61)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.readProperties(MappingMongoConverter.java:378)
For attention, the code works fine with spring-boot 1.5.x and spring-data 1.x.
What can I do to solve this issue?
Seems many similar exception reports below:
Spring boot 2.1.0 security change with kotlin data class?
https://github.com/arangodb/spring-data/issues/123
https://github.com/spring-projects/spring-boot/issues/15698
[Resolved] Works after fall back to Spring-boot 2.0.x and spring-data-commons 2.0.x. Will keep 2.1 excluded in future upgrading plans.
mongodb kotlin spring-data spring-data-mongodb
Environment:
Spring-boot 2.1.2.RELEASE,
Spring-data 2.1.4.RELEASE,
Kotlin 1.2.x ~ 1.3.x,
Mongodb.
I defined a model class like:
@Document
class MeAccount : Setting() {
lateinit var id: String
val accountEntries = listOf<BankAccount>()
}
When I tried to read this model from mongodb, I got exception stacktrace blow:
java.lang.UnsupportedOperationException: No accessor to set property private final java.util.List com.xxx.MeCustodianAccount.accountEntries!
at com.xxx.MeCustodianAccount_Accessor_fs514j.setProperty(Unknown Source)
at org.springframework.data.mapping.model.ConvertingPropertyAccessor.setProperty(ConvertingPropertyAccessor.java:61)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.readProperties(MappingMongoConverter.java:378)
For attention, the code works fine with spring-boot 1.5.x and spring-data 1.x.
What can I do to solve this issue?
Seems many similar exception reports below:
Spring boot 2.1.0 security change with kotlin data class?
https://github.com/arangodb/spring-data/issues/123
https://github.com/spring-projects/spring-boot/issues/15698
[Resolved] Works after fall back to Spring-boot 2.0.x and spring-data-commons 2.0.x. Will keep 2.1 excluded in future upgrading plans.
mongodb kotlin spring-data spring-data-mongodb
mongodb kotlin spring-data spring-data-mongodb
edited Jan 21 at 7:05
Jack Zhu
asked Jan 20 at 6:51
Jack ZhuJack Zhu
1318
1318
2
valproperties don’t have a setter. Change it tovar
– Strelok
Jan 20 at 6:55
@Strelok that is totally unacceptable, val is my admirable feature from kotlin. And the code works with spring-data 1.12.x.
– Jack Zhu
Jan 20 at 6:59
1
Welp, sorry, but that's a fact. Vals in the body need to be initialized in the init block, constructor, or or inline. They don't have a setter
– Zoe
Jan 20 at 17:02
Have you considered making this adataclass and moving the properties into the constructor? As you have it now, nothing (including Spring Data MongoDB) can ever set the value foraccountEntries.
– Mark B
Jan 20 at 17:55
As I said, the 'val' is the most wanted feature of kotlin for us, and the code failed because spring-data 2.1.x breaks the compatiblility. @Mark B The code works totally fine in former spring-data releases.
– Jack Zhu
Jan 21 at 3:50
|
show 1 more comment
2
valproperties don’t have a setter. Change it tovar
– Strelok
Jan 20 at 6:55
@Strelok that is totally unacceptable, val is my admirable feature from kotlin. And the code works with spring-data 1.12.x.
– Jack Zhu
Jan 20 at 6:59
1
Welp, sorry, but that's a fact. Vals in the body need to be initialized in the init block, constructor, or or inline. They don't have a setter
– Zoe
Jan 20 at 17:02
Have you considered making this adataclass and moving the properties into the constructor? As you have it now, nothing (including Spring Data MongoDB) can ever set the value foraccountEntries.
– Mark B
Jan 20 at 17:55
As I said, the 'val' is the most wanted feature of kotlin for us, and the code failed because spring-data 2.1.x breaks the compatiblility. @Mark B The code works totally fine in former spring-data releases.
– Jack Zhu
Jan 21 at 3:50
2
2
val properties don’t have a setter. Change it to var– Strelok
Jan 20 at 6:55
val properties don’t have a setter. Change it to var– Strelok
Jan 20 at 6:55
@Strelok that is totally unacceptable, val is my admirable feature from kotlin. And the code works with spring-data 1.12.x.
– Jack Zhu
Jan 20 at 6:59
@Strelok that is totally unacceptable, val is my admirable feature from kotlin. And the code works with spring-data 1.12.x.
– Jack Zhu
Jan 20 at 6:59
1
1
Welp, sorry, but that's a fact. Vals in the body need to be initialized in the init block, constructor, or or inline. They don't have a setter
– Zoe
Jan 20 at 17:02
Welp, sorry, but that's a fact. Vals in the body need to be initialized in the init block, constructor, or or inline. They don't have a setter
– Zoe
Jan 20 at 17:02
Have you considered making this a
data class and moving the properties into the constructor? As you have it now, nothing (including Spring Data MongoDB) can ever set the value for accountEntries.– Mark B
Jan 20 at 17:55
Have you considered making this a
data class and moving the properties into the constructor? As you have it now, nothing (including Spring Data MongoDB) can ever set the value for accountEntries.– Mark B
Jan 20 at 17:55
As I said, the 'val' is the most wanted feature of kotlin for us, and the code failed because spring-data 2.1.x breaks the compatiblility. @Mark B The code works totally fine in former spring-data releases.
– Jack Zhu
Jan 21 at 3:50
As I said, the 'val' is the most wanted feature of kotlin for us, and the code failed because spring-data 2.1.x breaks the compatiblility. @Mark B The code works totally fine in former spring-data releases.
– Jack Zhu
Jan 21 at 3:50
|
show 1 more comment
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54274248%2fspring-data-2-1-get-unsupportedoperationexception-no-accessor-to-set-property%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54274248%2fspring-data-2-1-get-unsupportedoperationexception-no-accessor-to-set-property%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
valproperties don’t have a setter. Change it tovar– Strelok
Jan 20 at 6:55
@Strelok that is totally unacceptable, val is my admirable feature from kotlin. And the code works with spring-data 1.12.x.
– Jack Zhu
Jan 20 at 6:59
1
Welp, sorry, but that's a fact. Vals in the body need to be initialized in the init block, constructor, or or inline. They don't have a setter
– Zoe
Jan 20 at 17:02
Have you considered making this a
dataclass and moving the properties into the constructor? As you have it now, nothing (including Spring Data MongoDB) can ever set the value foraccountEntries.– Mark B
Jan 20 at 17:55
As I said, the 'val' is the most wanted feature of kotlin for us, and the code failed because spring-data 2.1.x breaks the compatiblility. @Mark B The code works totally fine in former spring-data releases.
– Jack Zhu
Jan 21 at 3:50