想用 JPA criteria 構造動態查詢,其中一步是將 class entity 生成對應的 class entity_,方法有二:
1、在 settings 里勾選 annotation processors
2、在 pom.xml 內寫 maven plugin
想用2,網上 plugin 寫法有多種,不管用哪種,build project、rebuild project、maven compile,都沒有生成 class entity_
已試過以下 plugin 寫法(1-3用 maven-compiler-plugin ):
1、2.1.2. Usage with Maven
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
<compilerArguments>
<processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>
</compilerArguments>
</configuration>
</plugin>
2、JPA Criteria Metamodel Generation and Usage Guide
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<annotationProcessorPaths>
<annotationProcessorPath>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>${hibernate.version}</version>
</annotationProcessorPath>
</annotationProcessorPaths>
</configuration>
</plugin>
3、Hibernate JAP 元模型(Metamodel)
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<annotationProcessorPaths>
<path>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>5.4.3.Final</version>
</path>
</annotationProcessorPaths>
<generatedSourcesDirectory>target/metamodel</generatedSourcesDirectory>
</configuration>
</plugin>
4、Hibernate Tips: How to automatically add Metamodel classes to your project
<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>
5、JPA Hibernate Metamodel generation through maven(題主答主2種都試過)
1-3 用 maven-compiler-plugin,總是:[INFO] Nothing to compile - all classes are up to date
不管用哪種寫法,除了提示需補<version>,并沒有中止編譯的 ERROR 或 WARNING
請問:
1、既然各種寫法都明確能用,我少設定了哪里?
2、maven-compiler-plugin 寫法簡潔,怎樣正確設定?
困擾多時,望指點,非常謝謝
環境:
JDK 1.8
Kotlin 1.3.72
IDEA 社區版 2018.3.6
Spring 5.2.13(core、context、data-jpa 等,同版本號)
Hibernate 5.4.30(core、jpamodelgen、entitymanager 等,同版本號)
Maven 3.3.9
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/276832.html
標籤:Java EE
