-
Notifications
You must be signed in to change notification settings - Fork 358
Field access methods are not called when persisting Java 16 records #1138
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
Comments
I'd assume this is probably a |
While I agree with @schauder that this is an aspect of Spring Data Commons, everything works as designed. Spring Data uses field access by default. If you want Spring Data to use property accessors, please use the |
@mp911de Is there a way to set PROPERTY access for all entities in one place except setting |
There's no global flag to switch to property accessors for all properties. You could wrap |
@mp911de To avoid reflection and have standard java calls. |
Spring Data generates bytecode that uses method handles to interact with fields and you get the same performance as with native method calls. Having standard calls to methods would raise the general question of why using an object-mapper in the first place instead of providing your own |
I suppose I wanted to have cake and eat it too. ;-) Have standard calls and at the same time avoid manual |
There are efforts to optimize these accesses even more by generating Java code ahead of time with Spring Native/Spring AOT. These efforts could help to avoid runtime class generation in the first place but performance-wise it would lead to the same profile and it would not change the amount of classes loaded at runtime. |
When new Java record is persisted using repository's
save
method field access methods of the record are not called to read state of the passed record.Minimal reproducible example: hajdamak/spring-data-jdbc-record-access
Requires Maven and JDK17.
Call
mvn spring-boot:run
.Relevant output:
The text was updated successfully, but these errors were encountered: