This is a completely personal memo. It's a good level on Twitter, but here to leave it.
When I somehow created the Entity class used in Spring Data MongoDB, I got an error. I get an error saying "Setter". If you try it with a Setter, it will certainly work. But why did you just find One and return it? ?? ??
error
This application has no configured error view, so you are seeing this as a fallback.
Mon Feb 18 06:27:46 JST 2019
There was an unexpected error (type=Internal Server Error, status=500).
No accessor to set property @org.springframework.data.annotation.Id()private final java.lang.Integer com.example.demo.Flower.id!
java.lang.UnsupportedOperationException: No accessor to set property @org.springframework.data.annotation.Id()private final java.lang.Integer com.example.demo.Flower.id!
at com.example.demo.Flower_Accessor_jjo0e1.setProperty(Unknown Source)
at org.springframework.data.mapping.model.ConvertingPropertyAccessor.setProperty(ConvertingPropertyAccessor.java:61)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.readAndPopulateIdentifier(MappingMongoConverter.java:326)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.populateProperties(MappingMongoConverter.java:289)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:275)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:245)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:194)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:190)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:78)
at org.springframework.data.mongodb.core.ReactiveMongoTemplate$ReadDocumentCallback.doWith(ReactiveMongoTemplate.java:2910)
at reactor.core.publisher.FluxMapFuseable$MapFuseableSubscriber.onNext(FluxMapFuseable.java:107)
at reactor.core.publisher.FluxOnAssembly$OnAssemblySubscriber.onNext(FluxOnAssembly.java:353)
at reactor.core.publisher.MonoNext$NextSubscriber.onNext(MonoNext.java:76)
at com.mongodb.reactivestreams.client.internal.ObservableToPublisher$1.onNext(ObservableToPublisher.java:68)
...
If you try changing the code a little or read the big error carefully ... Ah, if you make it final, it won't work at Convert. Understood by the atmosphere.
Even without the setter, it worked when I removed only the final. There are various things behind the scenes.
@Document
public class Flower {
@Id
private Integer id;
private String name;
private String color;
Flower(){
id = null;
name = "";
color = "";
}
Flower(int id, String name, String color){
this.id = id;
this.name = name;
this.color = color;
}
public Integer getId() {
return this.id;
}
public String getName() {
return this.name;
}
public String getColor() {
return this.color;
}
}
Recommended Posts