我使用带有Gradle的JHipster生成应用程序作为构建工具。
当我创建实体时,我添加了过滤支持,它生成了JPA静态元模型。但是IntelliJ并没有认识到元模型。
我已在IntelliJ上启用了注释处理器设置,但它似乎无法正常工作。
我需要更改哪些设置才能让IntelliJ识别JPA静态元模型?
答案 0 :(得分:2)
不允许发表评论,但我想补充一下Thorben Janssen的答案。 除了插件配置,我还必须将其添加到项目的依赖项中:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>5.4.21.Final</version>
</dependency>
这是在目标/生成源/注释路径中生成源的原因。
所以pom最终像这样:
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>5.4.21.Final</version>
</dependency>
...
</dependencies>
...
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>add-source</id>
<goals>
<goal>add-source</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<sources>
<source>target/generated-sources/annotations</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
...
</build>
答案 1 :(得分:1)
By default, the metamodel classes get generated into the /target/generated-sources/annotations
folder. It seems like that folder isn't registered as a source folder.
You can either change that manually in your IDE or if you're using a Maven build, you can do that automatically by adding the following plugin to your build configuration:
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>target/generated-sources/annotations</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
...
</project>
I explained that in more details in one of my Hibernate Tips.
答案 2 :(得分:0)
Intellij的构建识别此文件中列出的所有处理器:
META-INF /服务/ javax.annotation.processing.Processor
使用Eclipse Link的情况,请在文件中包含以下行:
org.eclipse.persistence.internal.jpa.modelgen.CanonicalModelProcessor
Case Hibernate:
org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor
确保您拥有所有依赖关系:我将使用maven进行描述,例如:
objects
OR
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.jpa.modelgen.processor</artifactId>
<version>2.7.0</version>
<scope>provided</scope>
</dependency>
答案 3 :(得分:0)
要让IntelliJ IDEA识别生成的类,我必须在build.gradle
上添加这一行
sourceSets {
main.java.srcDirs += 'build/generated/source/apt/main'
}
<强>更新强>
更好的解决方案是修改IntelliJ插件
idea {
module {
sourceDirs += file("build/generated/source/apt/main")
generatedSourceDirs += file("build/generated/source/apt/main")
}
}