为了账号安全,请及时绑定邮箱和手机立即绑定

在 Maven 中配置 hibernate-jpamodelgen

在 Maven 中配置 hibernate-jpamodelgen

慕码人8056858 2023-05-10 13:51:40
我想配置hibernate-jpamodelgen到 Maven 中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 http://maven.apache.org/xsd/maven-4.0.0.xsd">    <modelVersion>4.0.0</modelVersion>    <groupId>plugin</groupId>    <artifactId>org.plugin</artifactId>    <version>1.0</version>    <packaging>jar</packaging>    <name>Plugin</name>    <url>http://maven.apache.org</url>    <parent>         ........        <dependency>            <groupId>org.hibernate</groupId>            <artifactId>hibernate-jpamodelgen</artifactId>            <version>5.4.3.Final</version>            <scope>provided</scope>        </dependency>    </dependencies>    <build>        <finalName>datalis_plugin</finalName>        <plugins>            <plugin>                <groupId>org.apache.maven.plugins</groupId>                <artifactId>maven-compiler-plugin</artifactId>                <version>3.8.1</version>                <configuration>                    <source>10</source>                    <target>10</target>                    <encoding>${project.build.sourceEncoding}</encoding>                    <annotationProcessorPaths>                        <path>                            <groupId>org.projectlombok</groupId>                            <artifactId>lombok</artifactId>                            <version>1.18.6</version>                        </path>                    </annotationProcessorPaths>                    <compilerArguments>                        <processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>                    </compilerArguments>                </configuration>            </plugin>                       </plugins>    </build>    <properties>        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>    </properties>   </project>完整 POM: https: //pastebin.com/VjucMAYL
查看完整描述

4 回答

?
偶然的你

TA贡献1841条经验 获得超3个赞

我通常只是将 hibernate-jpamodelgen 添加到编译器插件的 annotationprocessorpath 中。这可以防止处理器被打包到部署中。


 <plugin>

    <groupId>org.apache.maven.plugins</groupId>

    <artifactId>maven-compiler-plugin</artifactId>

    <configuration>

      <annotationProcessorPaths>

        <path>

          <groupId>org.mapstruct</groupId>

          <artifactId>mapstruct-processor</artifactId>

          <version>${org.mapstruct.version}</version>

        </path>

        <path>

          <groupId>org.hibernate</groupId>

          <artifactId>hibernate-jpamodelgen</artifactId>

          <version>5.4.3.Final</version>

        </path>

      </annotationProcessorPaths>

    

    </configuration>

  </plugin>


查看完整回答
反对 回复 2023-05-10
?
料青山看我应如是

TA贡献1772条经验 获得超7个赞

<scope>provided</scope>从中删除


    <dependency>

        <groupId>org.hibernate</groupId>

        <artifactId>hibernate-jpamodelgen</artifactId>

        <version>5.4.3.Final</version>

    </dependency>

添加插件


    <plugins>

        ...

        <plugin>

            <groupId>org.bsc.maven</groupId>

            <artifactId>maven-processor-plugin</artifactId>

            <version>3.1.0</version>

            <executions>

                <execution>

                    <id>process</id>

                    <goals>

                        <goal>process</goal>

                    </goals>

                    <phase>generate-sources</phase>

                    <configuration>

                        <processors>

                            <processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>

                        </processors>

                    </configuration>

                </execution>

            </executions>

            <dependencies>

                <dependency>

                    <groupId>org.hibernate</groupId>

                    <artifactId>hibernate-jpamodelgen</artifactId>

                    <version>5.4.3.Final</version>

                </dependency>

            </dependencies>

        </plugin>

        ...

    </plugins>

然后重建


mvn clean package -DskipTests


查看完整回答
反对 回复 2023-05-10
?
陪伴而非守候

TA贡献1757条经验 获得超8个赞

如果是 Java 12,请在 pom.xml 中的构建中使用以下代码片段。


<plugin>

    <groupId>org.apache.maven.plugins</groupId>

    <artifactId>maven-compiler-plugin</artifactId>

    <version>3.8.0</version>

    <configuration>

        <release>12</release>  

    </configuration>

</plugin>

在此之后,为 jpamodelgen 添加以下内容。


<dependency>

  <groupId>org.hibernate</groupId>

  <artifactId>hibernate-jpamodelgen</artifactId>

  <version>5.4.3.Final</version>

  <optional>true</optional>

</dependency>


查看完整回答
反对 回复 2023-05-10
?
眼眸繁星

TA贡献1873条经验 获得超9个赞

这对我有用


pom.xml:


<dependencies>

    <dependency>

        <groupId>org.hibernate</groupId>

        <artifactId>hibernate-jpamodelgen</artifactId>

        <scope>provided</scope>

    </dependency>

</dependencies>


<build>

  <plugins>

    <plugin>

        <groupId>org.apache.maven.plugins</groupId>

            <artifactId>maven-compiler-plugin</artifactId>

            <configuration>

                <source>11</source>

                <target>11</target>

                <annotationProcessorPaths>

                    <path>

                        <groupId>org.springframework.boot</groupId>

                        <artifactId>spring-boot-configuration-processor</artifactId>

                        <version>2.2.11.RELEASE</version>

                    </path>

                    <path>

                        <groupId>org.hibernate</groupId>

                        <artifactId>hibernate-jpamodelgen</artifactId>

                            <version>5.4.22.Final</version>

                    </path>

                </annotationProcessorPaths>

            </configuration>

        </plugin>

  </plugins>

</build>


<profiles>

  <profile>

        <id>dev</id>

        <activation>

            <activeByDefault>true</activeByDefault>

        </activation>

        <dependencies>

            <dependency>

                <groupId>org.hibernate</groupId>

                <artifactId>hibernate-jpamodelgen</artifactId>

            </dependency>

        </dependencies>

        <properties>

            <spring.profiles.active>dev</spring.profiles.active>

        </properties>

    </profile>

</profiles>

import com.mycompany.myapp.domain.*; // for static metamodels

import com.mycompany.myapp.domain.User


public class UserQueryService {


private Specification<User> createSpecification(UserCriteria criteria) {

  Specification<User> specification = Specification.where(null);

  if (criteria != null) {

    if (criteria.getId() != null) {

       specification = specification.and(buildSpecification(criteria.getId(), User_.id));

    }

  }

  return specification;

}    

}


查看完整回答
反对 回复 2023-05-10
  • 4 回答
  • 0 关注
  • 164 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信