Eclipse中Jakarta栈JPA元模型生成升级故障排查求助
升级Jakarta EE 10后JPA元模型生成失败问题
背景
原有基于Java EE 8栈的Maven项目,在Eclipse 2022-06(Java 11)环境下可正常构建,通过eclipselink-maven-plugin 2.7.5.1实现增量自动生成JPA元模型,配置如下:
<plugin> <groupId>com.ethlo.persistence.tools</groupId> <artifactId>eclipselink-maven-plugin</artifactId> <configuration> <generatedSourcesDirectory>${project.basedir}/src/main/jpa-metamodel</generatedSourcesDirectory> </configuration> <executions> <execution> <id>generate-jpa-metamodels</id> <phase>generate-sources</phase> <goals> <goal>modelgen</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>build-helper-maven-plugin</artifactId> <executions> <execution> <id>add-source</id> <phase>generate-sources</phase> <goals> <goal>add-source</goal> </goals> <configuration> <sources> <source>${project.basedir}/src/main/jpa-metamodel</source> </sources> </configuration> </execution> </executions> </plugin>
该配置可正确让Eclipse识别新源码目录并实现元模型的增量构建。
升级后异常情况
升级至Jakarta EE 10,将eclipselink-maven-plugin升级至3.0.2,同时Eclipse升级为2023-09、Java版本切换为21后,项目更新及「Run As > Maven goal」操作失效,无法覆盖已生成的元模型构件,报错信息如下:
Hibernate JPA 2 Static-Metamodel Generator 6.2.0.CR4 Problem with Filer: Attempt to recreate a file for type ...
注:右键菜单执行「Run As > Maven goal」(如
Maven test)会失败,但通过自定义运行配置设置目标为clean test时可正常工作。
需求与参考信息
已在相关社区讨论中看到此被标注为预期行为,但未找到eclipselink-maven-plugin中导致该问题的具体变更点,现寻求解决建议、修复方案或规避办法。
补充:已存在最小可复现示例项目。
参考资料:
- Hibernate社区论坛关于「Problem with Filer: Attempt to recreate a file for type」错误的讨论
eclipselink-maven-plugin的GitHub Issue #44
内容的提问来源于stack exchange,提问作者Claudio Weiler
相关产品推荐
相关产品推荐

