These error occurs when selecting columns from the database that don’t match the model, for example:
org.springframework.dao.DataIntegrityViolationException: Error attempting to get column 'name' from result set. Cause: java.sql.SQLDataException: Cannot determine value type from string 'singming'
org.springframework.dao.DataIntegrityViolationException: Error attempting to get column 'type' from result set. Cause: java.sql.SQLDataException: Cannot convert string 'MALE' to java.sql.Timestamp value
Ensure your SQL query only selects columns that exist in your Java model to avoid type mismatches and data integrity issues.
The error looks ridiculous, it is because mybatis is trying to map results from sql to some fields in the java model. e.g. mapping a
name VARCHAR(255) to
Date createdTime even if you add the
jdbcType mapping in the
MyBatis expects a direct mapping between columns in your SQL query and properties in your Java model. If your SQL query selects columns that don’t exist in your model, you can encounter type mismatches errors above.
To resolve this:
Review your SQL queries: Ensure that you only select columns that have corresponding properties in your Java model.
Use aliases: If your SQL query retrieves columns with different names but equivalent data, use aliases to match them to the model properties.
<!-- MyBatis XML Mapper -->
// Java model
In this example, the SQL query and Java model are aligned, resulting in a smooth mapping without type mismatches.