Handling of null values without global configuration

34 views
Skip to first unread message

Kevin Chee

unread,
Dec 9, 2020, 2:55:37 AM12/9/20
to mybatis-user
Hi, I have a query that retrieves Data from tables dynamically depending on the Table name. Currently the result is being stored in a hashmap, but it omits out null values.

I have attempted callSettersOnNulls and using Custom TypeHandler but they both have to be declared in the global configuration. I have tried resultmap and attaching the TypeHandler to the column. But the query is dynamic so i would not be able to attach it to a column.

Is there a way that i can allow the hashmap to retain null values? or have the Custom TypeHandler only applies to this query? Thanks

Kevin Chee

unread,
Dec 9, 2020, 2:58:09 AM12/9/20
to mybatis-user

Kevin Chee

unread,
Dec 9, 2020, 2:59:18 AM12/9/20
to mybatis-user
<select id="getContent" resultType="java.util.HashMap"> 
             SELECT '${table}' as TABLE, B.* 
             FROM 
            ${table} B WHERE id = #{id} 
</select>  

On Wednesday, 9 December 2020 at 15:55:37 UTC+8 Kevin Chee wrote:

Iwao AVE!

unread,
Dec 10, 2020, 2:01:02 PM12/10/20
to mybatis-user
Hello Kevin,

If you cannot enable callSettersOnNulls, you may have to create a separate statement for that specific table with a POJO as its resultType.

Although there are exceptions, such a 'universal' select that returns a Map is an anti-pattern in general.
And the fact that you need the special null treatment implies that this particular query is different from the others.

Regards,
Iwao


--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mybatis-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/2173073b-da3b-40f5-84ad-02ae78f39846n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages