Haskell Fun Haskell Fun - 5 days ago 5
Java Question

How does it work ? Dot notation on null - mybatis

When I do:

insert into .... values (...,#{object.intField, javaType=Integer},...)#
then it is working - in database this column contains
null
- as expected. How does it work under hood ? I mean, that
object
is null, altohugh it works. Where is the magic ?

Answer

Parameters values are resolved from the method org.apache.ibatis.scripting.defaults.DefaultParameterHandler.setParameters(PreparedStatement)

Then the magic you are looking for is here: method org.apache.ibatis.reflection.MetaObject.getValue(String) tokenizes parameter name string, splitting on dots, and is recursively called until the end of the chain is reached or until the current element is null.

After that we are back to the general case: object properties values are retrieved by reflection: down to java.lang.reflect.Field.