[JAVA] Error when the member of Entity class used in SpringWebFlux is final

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

Error when the member of Entity class used in SpringWebFlux is final
The idea of cutting off when the error is not resolved
When the bean class name is duplicated
Possibility when deploying to EC2 but nothing is displayed in the error log
When you get lost in the class name
[Ruby] Meaning of &. How to avoid the error when the receiver (object) is nil
[Java] Where is the implementation class of annotation that exists in Bean Validation?
Cause of is not visible when calling a method of another class in java
[Java] Calculate the day of the week from the date (Calendar class is not used)
When the project is not displayed in eclipse
How to get the class name of the argument of LoggerFactory.getLogger when using SLF4J in Java
When the hover of Eclipse is hard to see
In Time.strptime,% j (total date of the year) is
Return the execution result of Service class in ServiceResponse class
Get the name of the test case in the JUnit test class
When the month of the date is acquired, the January shift
Personal summary of the guys often used in JUnit 4
[Error] The app is not displayed in the production environment
Why the get method is needed in the Calendar class
Summarize the additional elements of the Optional class in Java 9
When rewriting the CMD of docker image of Pod in the manifest of k8s, command is not good
[Ruby] Thinking when there is no receiver in front of the method (it looks like)
wsimport error handling (A class / interface with the same name "xxx" is already in use)
Determine that the value is a multiple of 〇 in Ruby
When using the constructor of Java's Date class, the date advances by 1900.
What is the representation of domain knowledge in the [DDD] model?
Error in production environment (The asset "~" is not present in the asset pipeline.)
[Rails] When the layout change of devise is not reflected
An error occurs when codedeploy-agent is installed in Ubuntu Server 20.04
Behavior when each is executed in the reverse order Range
[Swift] Get the timing when the value of textField is changed
A memo of the update command when npm install causes an error in GitHub Action etc.
The behavior of Class # getClassLoader changes depending on whether it is executed in the IDE or jar.
I want to make the frame of the text box red when there is an input error
Static function to check if the RGB error of BufferdImage is within the specified ratio in Java
What is the BufferedReader class?
Symbol not found error when new class in another Java file
Handle business logic for a set of Entity in Java class
The repository ... is not signed error in docker build apt-get update
How to output the value when there is an array in the array
A memorial service for the library used when competing in Ruby
Mechanism and characteristics of Collection implementation class often used in Java
The milliseconds to set in /lib/calendars.properties of Java jre is UTC
What is @Override or @SuppressWarnings ("SleepWhileInLoop") in front of the function? ?? ??
Examine the list of timezone IDs available in the Java ZoneId class
[Reference example] Copyright is described in the comment of the source code.
How to solve the unknown error when using slf4j in Java
[Spring Boot] Until @Autowired is run in the test class [JUnit5]
Investigation method when the CPU of the server running java is heavy
Unknown error in line 1 of pom.xml when using Spring Boot in Eclipse
How to write the view when Vue is introduced in Rails?
[RSpec] When you want to use the instance variable of the controller in the test [assigns is not recommended]
[Spring Boot] List of validation rules that can be used in the property file for error messages