mybatis-mapper / mapper

MyBatis Mapper
https://mapper.mybatis.io
Apache License 2.0
326 stars 48 forks source link

使用jpa注解报错 #10

Closed JimmyiZhang closed 2 years ago

JimmyiZhang commented 2 years ago

使用jpa注解报错(针对支持部分)

@Data
@Table(name = "account")
public class Account {
    @Id
    @Column(name = "id")
    private Long id;
    @Column(name = "name")
    private String name;
}

使用selectByPrimaryKey(Long id),报错信息如下:

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.builder.BuilderException: Error invoking SqlProvider method 'public static java.lang.String io.mybatis.mapper.base.EntityProvider.selectByPrimaryKey(org.apache.ibatis.builder.annotation.ProviderContext)' with specify parameter 'class java.lang.Long'.  Cause: java.lang.RuntimeException: Can't obtain selectById method corresponding entity class

版本信息

java17

<dependency>
    <groupId>io.mybatis</groupId>
    <artifactId>mybatis-mapper</artifactId>
    <version>1.0.1</version>
</dependency>

补充信息

使用@Entity.XXX注解可以 通过查看jar未发现io.mybatis.provider.jpa包的相关实现

abel533 commented 2 years ago

异常不够完整。

是否添加了 mybatis-jpa 的依赖?

JimmyiZhang commented 2 years ago

原因是:没有引用mybatis-jpa依赖

<dependency>
    <groupId>io.mybatis</groupId>
    <artifactId>mybatis-jpa</artifactId>
    <version>1.0.1</version>
</dependency>

文档中没有提及 或者我可以帮忙完善

abel533 commented 2 years ago

默认是不包含 jpa 的。。如果你在用 mybatis-jpa,欢迎参与项目、完善文档。