Skip to content

Objects instantiated when all fields in a ResultMap are null #421

@jpeffer

Description

@jpeffer

Empty objects are instantiated when all fields in a ResultMap are null and an ID tag is present, regardless of whether that defined ID is mapped to a property.

Consider the following ResultMap definition:

<resultMap id="employeesInEstablishment" type="Person">
    <id column="establishment_id"/>
    <result property="firstName"  column="owner_first_name" />
    <result property="lastName"  column="owner_last_name" />
</resultMap>

This result map has a 1-many relationship with an Establishment, which has an establishment ID. The select statement and result maps are much more complex than this, but I am trying to simplify the issue down to what I believe to be the root cause.

When retrieving establishment results, regardless of dealing with an association or collection, I end up with empty objects within my Establishment, even if, in the example above, first and last name columns are null.

When the ID tag is removed, this behavior does not occur, but after profiling the application, the number of invocations on resultSet.getString literally doubles, from ~11k to ~26k.

It would make sense for MyBatis to ignore IDs that are not mapped to a property within the associated resultMap type's object, when deciding to instantiate the object or not. This would allow for mapping to be optimized while avoiding instantiation of empty objects, which later causes serialization issues to json.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions