Skip to content

Conversation

@harawata
Copy link
Member

@harawata harawata commented Oct 8, 2016

When a query returns a row with all columns being null (= an empty row), MyBatis returns null by default.
As per users' requests, a new configuration option returnInstanceForEmptyRow is added to change this behavior.
With this option enabled, MyBatis returns an empty instance instead of null for an empty row.

Note that this option also generates an empty instance for nested results (i.e. <collection /> and <association />) to meet a requirement like #420 .
To control this behavior individually, you may have to specify notNullColumn.

Please refer to the attached test cases for how it works and test your solutions with the latest 3.4.2-SNAPSHOT.

🔹 The existing option callSettersOnNulls is whether to call the property's setter method when the column value is null, so it has no effect on the above behavior. In version 3.2.x, it affected the returned value unintentionally.

…at tells MyBatis to return an empty instance instead of null when all the columns of a row are NULL.
@nlenoire
Copy link

Hello,

it looks like it is not possible to apply this settings using a constructor, but only an association or a collection element. Would it be possible to support it in constructor as well, to accommodate with immutable objects?

@dpawlak-pgs
Copy link

Look like it's not working for object created via constructor?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Improve a feature or add a new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants