Skip to content

returnInstanceForEmptyRow does not work for constructor auto-mapping #2665

Closed

Description

@cvmocanu

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.

Activity

  1. harawata commented on Aug 26, 2022

    @harawata
    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.

  2. changed the title [-]`returnInstanceForEmptyRow` does not seem to work (at least in this case)[/-] [+]`returnInstanceForEmptyRow` does not work for constructor auto-mapping[/+] on Aug 27, 2022
  3. added a commit that references this issue on Aug 27, 2022
    7890232
  4. self-assigned this
    on Aug 27, 2022
  5. added this to the 3.5.11 milestone on Aug 27, 2022
  6. harawata commented on Aug 27, 2022

    @harawata
    Member

    @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!

  7. cvmocanu commented on Aug 29, 2022

    @cvmocanu
    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?

  8. added 2 commits that reference this issue on Sep 4, 2022
    9309407
    3229330
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions