Mybatis: Cannot determine value type from string ‘city2001’


When the entity class queried does not have a parameter free construction method, the query reports an error:

Cannot determine value type from string 'city2001'; nested exception is java.sql.SQLDataException: Cannot determine value type from string 'city2001'] with root cause


I vaguely remember that I created the full parameter construction method for entity classes, but forgot to add the non parameter construction method. The mapping mechanism of mybatis should be to use the set method for attribute mapping. When the non parameter construction method is gone, the new can’t get out of the object, so naturally it can’t be mapped automatically.

Entity class

public class Student implements Serializable {
    private static final long serialVersionUID = -49141689091044211L;
    private Long id;
    private String name;
    private String city;
    private Integer age;

    public Student(String name, String city, Integer age) { = name; = city;
        this.age = age;
    ... omit get set

Preliminary verification

Simple debug the source code, combined with the information on the Internet,org.apache.ibatis.executor.resultset.DefaultResultSetHandleMethods found in classcreateAutomaticMappings, which processes the prefix, determines whether there is a corresponding set method, and then injects it.

final String property = metaObject.findProperty(propertyName, configuration.isMapUnderscoreToCamelCase());
        if (property != null && metaObject.hasSetter(property)) {
          if (resultMap.getMappedProperties().contains(property)) {

Introduction Xiaobai, learning sparse shallow, if there are omissions, welcome to point out.

The first update time of this paper is April 28, 2020

The last update time of this paper is April 28, 2020 (if there is a breakthrough, keep updating)

Personal blog based on Halo:

Recommended Today

Python basics Chinese series tutorial · translation completed

Original: Python basics Python tutorial Protocol: CC by-nc-sa 4.0 Welcome anyone to participate and improve: a person can go very fast, but a group of people can go further. Online reading Apache CN learning resources catalog introduce Seven reasons to learn Python Why Python is great Learn Python introduction Executing Python scripts variable character string […]