‘org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor‘ 的受支持 source 版本 ‘RELEASE_6‘ 低于 -source ‘1.8‘

 运行某项目发现报错找不到类并发出警告:来自注释处理器 'org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor' 的受支持 source 版本 'RELEASE_6' 低于 -source '1.8',该类以下划线结尾(类名加下划线|ORM 对象加下划线),是JPA的Metamodel用法。

什么是 Metamodel

如果你使用 JPA 或者 Hibernate 写 criteriaQuery 的时候。

你可能会遇到下面一句话

criteriaQuery.where(builder.greaterThan(root.get("dateM"), new DateTime().minusDays(100).toDate()));

抛开上面所有的类型定义不说,上面这句话的意思就是创建一个 SQL 查询 dateM 字段更新时间大于当前时间减去 100 天的时间。

如果使用 Metamodel 的话,就可以写成:

criteriaQuery.where(builder.greaterThan(root.get(MlsListing_.DATE_M), new DateTime().minusDays(100).toDate()));

上面这句话查询的是 MlsListing_ORM 对象中的更新日期,与上面的那句话是等同的。

MlsListing_.DATE_M 就是我们说的 Metamodel 了,这个是动态生成的。

并且使用的是 ORM 对象加下划线的表达方式。

解决办法: 在IDEA中配置Annotation Processors即可

  In the annotation processor configuration, enable annotation processing and select obtain from project classpath. Add the annotation processor name org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor (and optionally the annotation processor options). Select the module(s) containing your entities. If you have configured Maven as recommended, it is best to select the same output directory for the generated classes. At the time of writing, it is target/generated-sources/apt. That way, the generated classes will be available in IntelliJ Idea.

参考文章:

1.JPA Static Metamodel Generator

2.JPA 的 Metamodel - Java - OSSEZ

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值