mapper bug report -

20 views
Skip to first unread message

QI LIANG

unread,
Jun 18, 2024, 2:43:16 AM (8 days ago) Jun 18
to mybatis-user
I have two tables, named tms_driver(primary table) and tms_account_resource_binding.

And SQL is here:
<select id="getDriverByLoginAccountId" resultType="org.jeecg.modules.driver.entity.Driver">
        SELECT
            td.*
        FROM
            tms_account_resource_binding tarb
                LEFT JOIN tms_driver td ON tarb.resource_id = td.id
        WHERE
            tarb.type = 1
            AND tarb.account_id = #{loginAccountId}
</select>


And I deleted the tms_driver's data.

I got a row of data with only tarb. But I need the data of td to complete the mapping

The mapper interface is defined as follows

 List<Driver> getDriverByLoginAccountId(@Param("loginAccountId") String loginAccountId) ;


 So I got a list has one item, like this:
 List<Driver> driverList = loginAccountMapper.getDriverByLoginAccountId(loginAccountId);
 driverList.size();// 1
 driverList.get(0).getCode();// NPE



Should we consider returning a null object at this time? rather than a List containing null objects

Iwao AVE!

unread,
Jun 18, 2024, 11:13:31 AM (8 days ago) Jun 18
to mybati...@googlegroups.com
Hello,

I'm not sure if I understand correctly, but it sounds like you need to use INNER JOIN instead of LEFT JOIN.
MyBatis still won't return null, but it will return an empty List.

Also, you might need to use a result map instead of relying on auto-mapping.

If you need further assistance, please create a demo project with a minimum set of tables/columns/classes and share it on your GitHub repository.
It's difficult to understand the problem only with partial information.
Here are some project templates and examples : https://github.com/harawata/mybatis-issues

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/3c931614-ab0d-4f7e-90bf-05bacc30e3d5n%40googlegroups.com.

QI LIANG

unread,
Jun 18, 2024, 8:44:19 PM (8 days ago) Jun 18
to mybatis-user
Thank you very much. I understand. I will consider your suggestion.

Peter Cao

unread,
Jun 19, 2024, 12:59:08 AM (8 days ago) Jun 19
to mybati...@googlegroups.com
You can take a look at DaoGenerate of JetBrains plugin, it can not only generate dao of single table,but also for query and master detail table, it’s very easy to use

Iwao AVE! <hara...@gmail.com>于2024年6月18日 周二23:13写道:
Reply all
Reply to author
Forward
0 new messages