我知道這個問題已經被問過好幾次了,但沒有一個答案對我有用。
基本上,我正在嘗試從我的物體生成 jpa 元模型,以便在規范中使用它們。然而,盡管運行(我認為,請參閱重建專案輸出螢屏截圖),Hibernate JPA 2 Static-Metamodel Generator 6.1.5.Final沒有在注釋檔案夾中生成任何類。
有人可以幫幫我嗎?(PS抱歉我不能發布截圖,因為堆疊溢位不允許我)
我正在使用帶有 sping boot 2.7.5 和 maven 和 intellij 的 java 19。
這是 Test.java 檔案(我要生成的類):
package com.example.demo.model;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
public class Test {
@Id
private int id;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
}
pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>19</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>6.1.5.Final</version>
</dependency>
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>4.0.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
重建專案輸出:
Clearing build system data...
Executing pre-compile tasks...
Cleaning output directories…
Running 'before' tasks
Checking sources
Copying resources... [demo]
Parsing java… [demo]
java: Hibernate JPA 2 Static-Metamodel Generator 6.1.5.Final
Writing classes… [demo]
Updating dependency information… [demo]
Adding @NotNull assertions… [demo]
Adding pattern assertions… [demo]
Adding Threading Model assertions… [demo]
Parsing java… [tests of demo]
Writing classes… [tests of demo]
Updating dependency information… [tests of demo]
Adding @NotNull assertions… [tests of demo]
Adding pattern assertions… [tests of demo]
Adding Threading Model assertions… [tests of demo]
Running 'after' tasks
javac 19 was used to compile java sources
Finished, saving caches…
Executing post-compile tasks...
Finished, saving caches…
Synchronizing output directories...
06-11-22 14:37 - Build completed successfully in 3 sec, 464 ms
和 intellij 注釋處理器設定:
我無法發布影像,但檢查了啟用注釋處理以及從 projet 類路徑獲取處理器,并且路徑是模塊內容根目錄中的 target\generated-sources\annotations。
重建專案后,會出現目標檔案夾,其中包含一個名為generated-sources的檔案夾。這個generate-sources包含一個名為annotations的檔案夾,但它不包含任何內容(但它應該包含類Test_)。
檔案夾注釋也已設定為源檔案夾。
我已經閱讀了一些以前的帖子,但沒有一個對我有用。我還閱讀了檔案(
- 第二種解決方案
將依賴項設定為最新版本(此處為 6.1.5.Final),但使用使用 5.6.12.Final 版本的 annotationProcessorPaths 將插件添加到構建中

PS:我不明白為什么變數${hibernate.version}設定為版本 5.6.12.Final 而我在依賴項中將我的休眠版本設定為 6.1.5.Final ......任何解釋都會很好: )
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/530332.html
