‘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

猜你喜欢

转载自blog.csdn.net/m0_75186659/article/details/128301734