Mybatis: Cannot determine value type from string ‘city2001’

Time:2020-5-22

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

guess

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 Student.java

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) {
        this.name = name;
        this.city = 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)) {
            continue;
          }
......
......

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: https://undivided.top

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 […]