yulichang / mybatis-plus-join

支持连表查询的mybatis-plus,mybatis-plus风格的连表操作提供wrapper.leftJoin(),wrapper.rightJoin()等操作
https://mybatis-plus-join.github.io
Apache License 2.0
1.18k stars 128 forks source link

MPJLambdaWrapper 空指针异常 #20

Closed wlhyl closed 6 months ago

wlhyl commented 2 years ago

多对多查询,三表left join,出现以下问题

Caused by: org.apache.ibatis.ognl.OgnlException: from [java.lang.NullPointerException: Cannot invoke "com.baomidou.mybatisplus.core.metadata.TableInfo.getTableName()" because the return value of "com.baomidou.mybatisplus.core.metadata.TableInfoHelper.getTableInfo(java.lang.Class)" is null]
Caused by: java.lang.NullPointerException: Cannot invoke "com.baomidou.mybatisplus.core.metadata.TableInfo.getTableName()" because the return value of "com.baomidou.mybatisplus.core.metadata.TableInfoHelper.getTableInfo(java.lang.Class)" is null

已经在entity上加了@TableName

表如下

@Data
@TableName("table_a")
public class TableA {
    @TableId(type = IdType.AUTO)
    private Long id;
    private String name;
}

@Data
@TableName("table_b")
public class TableB {
    @TableId(type = IdType.AUTO)
    private Long id;
    private String name;
}

@Data
@TableName("table_a_b")
public class TableAB{
    private Long aId;
    private Long bId;
}

查询

 var page = new Page<TableA>(1, 2);
var pages = TableAMapper.selectJoinPage(page, TableA.class, new MPJLambdaWrapper<TableA>()
                 .selectAll(TableA.class)
                .leftJoin(TableAB.class, TableAB::getAId, TableA::getId)
                .leftJoin(TableB.class, TableB::getId, TableAB::getBId));

jdk:

openjdk 17.0.4.1 2022-08-12 LTS
OpenJDK Runtime Environment Corretto-17.0.4.9.1 (build 17.0.4.1+9-LTS)
OpenJDK 64-Bit Server VM Corretto-17.0.4.9.1 (build 17.0.4.1+9-LTS, mixed mode, sharing)

mybatis plus 、mybatis plus join 、spring boot 版本

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.4</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
...
    <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.5.2</version>
        </dependency>

        <dependency>
            <groupId>com.github.yulichang</groupId>
            <artifactId>mybatis-plus-join</artifactId>
            <version>1.2.4</version>
        </dependency>
shallwetalkge commented 1 year ago

需要有Mapper extend MPJBaseMapper