首页 > 解决方案 > H2 - 发生了非法反射访问操作

问题描述

启动我的 spring-boot 应用程序后出现警告-

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.hibernate.internal.util.ReflectHelper (file:/C:/Users/xxxx/.m2/repository/org/hibernate/hibernate-core/5.3.7.Final/hibernate-core-5.3.7.Final.jar) to field java.lang.String.coder
WARNING: Please consider reporting this to the maintainers of org.hibernate.internal.util.ReflectHelper
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

结果我的表有一个 Coder 列,而不是像我的实体这样的实际名称 -

@Entity
public class TaxValuesEntity {

    @EmbeddedId
    public String countryCodePK;
    public double taxValue;
    public Timestamp creationAt;
    public Timestamp modifedAt;

    protected TaxValuesEntity() {
    };

    public TaxValuesEntity(String countryCode, double taxValue, Timestamp creation, Timestamp modifed) {
        this.countryCodePK = countryCode;
        this.taxValue = taxValue;
        this.creationAt = creation;
        this.modifedAt = modifed;
    }
    //getters & setters ...
};

感谢您的帮助,如果需要更多代码,请在下面评论。

标签: javaspring-bootentityh2

解决方案


我对 JDK11 和 Mockito 也有类似的问题。解决方法是使用最新版本的 Mockito。也许检查 Hibernate 的版本和 JDK 11 的当前支持状态。在快速搜索中,发现使用带有 jdk11的 hibernate和hibernate 版本 5.4


推荐阅读