baomidou / mybatis-plus

An powerful enhanced toolkit of MyBatis for simplify development
https://baomidou.com
Apache License 2.0
16.3k stars 4.3k forks source link

使用GraalVM打包时, 无法识别出实体类父类中的@TableId #6014

Closed 0xyk3r closed 6 months ago

0xyk3r commented 6 months ago

当前使用版本(必填,否则不予处理)

MybatisPlus 3.5.5 SpringBoot 3.2.4

该问题是如何引起的?(确定最新版也有问题再提!!!)

使用GraalVM打包时, 无法识别出实体类父类中的@TableId.

重现步骤(如果有就写完整)

以下是继承了BaseModel的一个实体类.

@Getter
@Setter
@Accessors(chain = true)
@NoArgsConstructor
@AllArgsConstructor
@TableName("sys_dict")
public class Dict extends BaseModel {
    @TableField("xxx")
    private String xxx;
    // ...
}

以下是BaseModel

@Data
@NoArgsConstructor
@AllArgsConstructor
public class BaseModel implements java.io.Serializable {
    @TableId(type = IdType.ASSIGN_ID)
    private String id;
    // ...
}

不使用GraalVM打包时没有此问题. 且该错误不影响list()等方法的查询.

报错信息

以下是GraalVM构建后, 运行后显示的警告信息.

2024-03-24 01:09:22 WARN  [           main] c.b.mybatisplus.core.metadata.TableInfoHelper      : Can not find table primary key in Class: "cn.projectan.aottest.model.db.Dict".
2024-03-24 01:09:22 WARN  [           main] c.b.mybatisplus.core.injector.DefaultSqlInjector   : class cn.projectan.aottest.model.db.Dict ,Not found @TableId annotation, Cannot use Mybatis-Plus 'xxById' Method.
0xyk3r commented 6 months ago

已解决, 但不确定是否有更好的解决方式.

RuntimeHintsRegistrar中添加以下代码.

hints.reflection().registerType(BaseModel.class, MemberCategory.values());