Whether Java Record class is supported in latest version. #3641
Replies: 1 comment 3 replies
-
|
The issue arises because Java Records are immutable by design. They do not have "setters" (setFieldName); instead, they have accessor methods (like fieldName()) and a canonical constructor that initializes all fields at once. MyBatis attempts to populate objects either via standard JavaBean setters or through a constructor. Since Records lack setters, MyBatis cannot find the "property" in the way it expects for regular POJOs. How to solve this: Constructor Mapping: MyBatis supports mapping result sets directly to the Record's constructor. Ensure your SQL column names match the Record component names (or use aliases). Enable mapUnderscoreToCamelCase: If your DB uses snake_case and your Record uses camelCase, enable this setting in your MyBatis configuration. This allows MyBatis to find the matching constructor parameters without needing setters. Explicit ResultMap: If the mapping is complex, use the element within a in your XML mapper to explicitly tell MyBatis which column goes to which Record component. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, here.
I'm using mybatis latest-version(3.5.19) discovery Record Class cannot find 'setter' property.
So let me ask the author or other users if they have encountered the same problem and how to solve it.
Beta Was this translation helpful? Give feedback.
All reactions