-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
IllegalAccessException when auto-mapping Records (JEP-359) #2195
Comments
This actually does work if you follow the directions for dealing with immutable objects and supply a constructor binding in a custom result map. Unfortunately, it is a lot more verbose than would be preferred. Maybe the code could check if the result type is a record and because result objects are always consistent in constructors it could automatically bind it together properly. Unfortunately, this probably relies on the isRecord method that does not exist before JDK 16. If the code allows for it maybe an optional adapter could be written that would allow for this support to be added for those of us on newer JDKs. If it does not allow for it currently maybe a new feature request could be submitted to allow for the code to allow something to hook in at the relevant location to supply this functionality? |
I will try to support the WDYT? |
@kazuki43zoo , |
@harawata Thanks for your reaction!! standard type: public class MyEntity {
private final Integer id;
private final String name;
public MyEntity(Integer id, String name) {
this.id = id;
this.name = name;
}
// ...
} recored type: public record MyEntity(Integer id, String name) {
} The standard type work but it write value to final field(
I agree with this!! |
Thank you, @kazuki43zoo for the information! I didn't know about the Anyway, my first impression is that this is an issue that should be addressed in [1] There is another outstanding feature request slightly related to this topic. It might be a good time to add support for the prefix-less getter/setter methods to |
FYI, I had record types working fine with JDK 14 in preview mode. But when I switched to JDK 16 (non-preview), I started running into the final field update error: java.lang.IllegalAccessException: Can not set final int field..... |
a next version with Record support would be great. @kazuki43zoo |
Pull request #2477 sent |
Agreed about the approach should be addressing Reflector. The reason it is trying to write to final field, is that it treat java record like any class, so it tries to
Dealing with java record like this actually is a problematic bug. My patch
That's it. You can see easily that in the case of java record, it might even be slightly faster :-) |
Thanks to @bzhou 's contribution, the problem with auto-mapping is fixed in the latest 3.5.10-SNAPSHOT. |
the xml mapping remains the same using immutable objects before JDK 16 record types ? |
I'm not sure if I understand correctly, but the reported error occurs when you rely on auto-mapping. As mentioned earlier, if you use properly configured |
Any release date forecast? |
I want MyBatis to Support for JDK 16 record types
The text was updated successfully, but these errors were encountered: