代码之家  ›  专栏  ›  技术社区  ›  Itsik Mauyhas

h2-发生了非法的反射访问操作

  •  0
  • Itsik Mauyhas  · 技术社区  · 6 年前

    启动我的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
    

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

    @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 ...
    };
    

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

    2 回复  |  直到 6 年前
        1
  •  0
  •   ctenescu    6 年前

    我对JDK11和Mockito也有类似的问题。修复方法是使用最新版本的mockito。可以检查Hibernate的版本和JDK 11的当前支持状态。在快速搜索中,找到了这个 using hibernate with jdk11 hibernate release 5.4

        2
  •  1
  •   user10639668    6 年前

    替换 EmbeddedId 具有 Id 这样地:

    import javax.persistence.Id;
    
    @Entity
    public class TaxValuesEntity {
    
        @Id
        public String countryCodePK;
    

    嵌入的 用于复合主键。