Skip to content
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

Regression: Constructor args fails on record types #2840

Open
jdmichal opened this issue Mar 7, 2023 · 2 comments
Open

Regression: Constructor args fails on record types #2840

jdmichal opened this issue Mar 7, 2023 · 2 comments

Comments

@jdmichal
Copy link

jdmichal commented Mar 7, 2023

MyBatis version

3.5.11 via mybatis-spring-boot-starter 2.3.0

Regression from 3.5.9 via mybatis-spring-boot-starter 2.2.2

Database vendor and version

PostgreSQL 14.x

Test case or example project

public record ResultType(
    String value) {
}
<resultMap id="resultTypeMap" type="ResultType">
    <constructor>
        <arg column="value" name="value" />
    </constructor>
</resultMap>

<select id="getResult" resultMap="resultTypeMap">
    SELECT 'foobar' AS value;
</select>

Steps to reproduce

  1. Create a record type and map to it via a constructor resultMap, as above.

Expected result

The default record constructor would be found and linked.

Actual result

The default record constructor is not found due to the java type of the ResultMapping being java.lang.Object.

Workaround

Define the javaType for the constructor args. This was not necessary in version 3.5.9.

@jdmichal jdmichal changed the title Regression: Constructor args fails on record / immutable types Regression: Constructor args fails on record types Mar 7, 2023
@jdmichal
Copy link
Author

jdmichal commented Mar 7, 2023

It appears that this is a duplicate of the closed #2803. However, it appears the PR that closed that issue is being withdrawn. So perhaps having this new issue open or closing this and reopening 2803 is appropriate.

As mentioned by @tzie0062 in that issue, this is a regression from 3.5.9 to 3.5.11. Some explanation seems in order for why this regression is taking place in a patch release, regardless of the attempt of #2804 to fix it.

@harawata
Copy link
Member

harawata commented Mar 7, 2023

Hello @jdmichal ,

It is the same issue as #2803 .
Here is the background.

It worked in 3.5.9 because the value was recognized as a writable property (which was clearly wrong).
It caused a problem with auto-mapping ( #2195 ), so we fixed it in 3.5.10.
As a result, value is no longer recognized as a writable property.

Now, as documented, in constructor mapping, javaType is required when there is no (writable) property with the same name and type.
This is why your result map stopped working in 3.5.10+ (it may work in 3.5.12, but it is just another 'accident' 😣 and we will release 3.5.13 ASAP).

It is unfortunate that it accidentally worked in ≤ 3.5.9 and I apologize for the confusion, but the right solution to your problem is to specify javaType instead of name.

This is going to be a FAQ, I imagine... 😔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants