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

returnInstanceForEmptyRow does not work for constructor auto-mapping #2665

Closed
cvmocanu opened this issue Aug 25, 2022 · 3 comments · Fixed by #2668
Closed

returnInstanceForEmptyRow does not work for constructor auto-mapping #2665

cvmocanu opened this issue Aug 25, 2022 · 3 comments · Fixed by #2668
Assignees
Labels
Milestone

Comments

@cvmocanu
Copy link

cvmocanu commented Aug 25, 2022

MyBatis version

3.5.10

Database vendor and version

PostgreSQL 11.6 (Debian 11.6-1.pgdg90+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 6.3.0-18+deb9u1) 6.3.0 20170516, 64-bit

Test case or example project

mybatis-bug.zip

Steps to reproduce

You need to have Java, Docker, and Docker-Compose installed.
From the root of the project:

  • docker-compose up -d
  • ./gradlew run

Expected result

The project prints ALL OK

Actual result

The project throws an exception got null row because all columns are null, even though returnInstanceForEmptyRow is true.

@harawata
Copy link
Member

Hello @cvmocanu ,

Thanks for the report & repro!

I could verify a problem (i.e. returnInstanceForEmptyRow is not correctly applied when MyBatis performs constructor-automapping), so I am going to fix it.
The attached test, however, kind of misses the point and I would like to clarify that.

As seen in the log, the query in the test does not return any row.

... PersonMapper.getById - ==>  Preparing: select name from person where id=?
... PersonMapper.getById - ==> Parameters: -1(Long)
... PersonMapper.getById - <==      Total: 0

When there is no row in the result set, MyBatis returns null even if returnInstanceForEmptyRow is enabled.
"empty row" means that there is a row in the result set and all mapped columns are NULL.
The option returnInstanceForEmptyRow was added to differentiate these two cases.

@harawata harawata changed the title returnInstanceForEmptyRow does not seem to work (at least in this case) returnInstanceForEmptyRow does not work for constructor auto-mapping Aug 27, 2022
harawata added a commit to harawata/mybatis-3 that referenced this issue Aug 27, 2022
@harawata harawata self-assigned this Aug 27, 2022
@harawata harawata added the bug label Aug 27, 2022
@harawata harawata added this to the 3.5.11 milestone Aug 27, 2022
@harawata
Copy link
Member

harawata commented Aug 27, 2022

@cvmocanu ,

I have committed the fix.

As I explained, the test you attached still fails.
Please let me know if you have any question.

Thanks again for your contribution!

@cvmocanu
Copy link
Author

@harawata, thanks so much.

I've fixed the example, in case it helps:
mybatis-bug-good-example.zip

Do you have an idea when the fix will be released?

IrvingOS pushed a commit to IrvingOS/mybatis-3 that referenced this issue Sep 4, 2022
IrvingOS pushed a commit to IrvingOS/mybatis-3 that referenced this issue Sep 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants