Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve type handler based on java.lang.reflect.Type instead of Class and respect runtime JDBC type #3379

Merged
merged 30 commits into from
Mar 15, 2025

Conversation

harawata
Copy link
Member

@harawata harawata commented Jan 3, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
# Conflicts:
#	src/main/java/org/apache/ibatis/builder/BaseBuilder.java
#	src/main/java/org/apache/ibatis/builder/MapperBuilderAssistant.java
#	src/main/java/org/apache/ibatis/builder/SqlSourceBuilder.java
#	src/main/java/org/apache/ibatis/builder/annotation/MapperAnnotationBuilder.java
#	src/main/java/org/apache/ibatis/builder/xml/XMLMapperBuilder.java
#	src/main/java/org/apache/ibatis/builder/xml/XMLStatementBuilder.java
#	src/main/java/org/apache/ibatis/executor/resultset/DefaultResultSetHandler.java
#	src/main/java/org/apache/ibatis/mapping/ParameterMapping.java
#	src/main/java/org/apache/ibatis/mapping/ResultMapping.java
#	src/main/java/org/apache/ibatis/reflection/MetaClass.java
#	src/main/java/org/apache/ibatis/reflection/Reflector.java
#	src/main/java/org/apache/ibatis/reflection/ReflectorFactory.java
#	src/main/java/org/apache/ibatis/scripting/defaults/DefaultParameterHandler.java
#	src/main/java/org/apache/ibatis/scripting/xmltags/XMLLanguageDriver.java
#	src/main/java/org/apache/ibatis/session/AutoMappingUnknownColumnBehavior.java
#	src/main/java/org/apache/ibatis/type/TypeHandlerRegistry.java
#	src/test/java/org/apache/ibatis/builder/XmlMapperBuilderTest.java
#	src/test/java/org/apache/ibatis/reflection/ReflectorTest.java
#	src/test/java/org/apache/ibatis/reflection/TypeParameterResolverTest.java
#	src/test/java/org/apache/ibatis/submitted/language/VelocitySqlSourceBuilder.java
@coveralls
Copy link

coveralls commented Jan 3, 2025

Coverage Status

coverage: 87.285% (+0.06%) from 87.226%
when pulling 949ccd3 on harawata:type-based-handler-resolution
into b90a0f8 on mybatis:master.

# Conflicts:
#	src/main/java/org/apache/ibatis/builder/SqlSourceBuilder.java
#	src/main/java/org/apache/ibatis/executor/resultset/DefaultResultSetHandler.java
#	src/main/java/org/apache/ibatis/scripting/defaults/DefaultParameterHandler.java
#	src/main/java/org/apache/ibatis/scripting/defaults/RawSqlSource.java
#	src/main/java/org/apache/ibatis/scripting/xmltags/DynamicSqlSource.java
… account

Fail-fast is nice, but it practically prevents MyBatis from using runtime JDBC type information to resolve type handler.

Related to mybatis#9 mybatis#19
@harawata harawata added the no backward compatibility Includes change no backward compatibility for previous version label Jan 29, 2025
@harawata harawata changed the title Resolve type handler based on java.lang.reflect.Type instead of Class Resolve type handler based on java.lang.reflect.Type instead of Class and respect runtime JDBC type Jan 29, 2025
…ndler

- Deprecated UnknownTypeHandler. Type handler resolution is delayed if not explicitly specified.
- Use registered type handler when retrieving OUT parameters. This could affect

- Changed the column order in `src/test/resources/org/apache/ibatis/submitted/nestedresulthandler_gh1551/ProductMapper.xml` as UnknownTypeHandler handled duplicate columns differently.
For "composite keys", the behavior changes depending on the existence of `parameterType`
When `parameterType` is not specified, parameter values are stored in a `Map` and custom type handler is not used.
When `parameterType="User"` is specified, `User` instance is created and properties are set using type handlers.
Related to mybatisgh-114

For "simple key", `parameterType` is ignored and custom type handler is not used at all.

I can think of some corner cases caused by these behaviors, but will deal with them when/if they come up.
…esolution
@harawata harawata marked this pull request as ready for review February 20, 2025 15:18
If a handler is registered against null JDBC type, it is the default handler for the Java type.
Users can override the default handler (e.g. `register(boolean.class, null, new YNBooleanTypeHandler())` or register a custom handler for a specific Java-JDBC type combination (e.g. `register(boolean.class, JdbcType.CHAR, new YNBooleanTypeHandler())`).

Type handlers in the `jdbcTypeHandlerMap` are used when Java type is unknown or as a last resort when no matching handler is found for the target Java type.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no backward compatibility Includes change no backward compatibility for previous version 🔩 typehandler
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants