亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在 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條經驗 獲得超8個贊

<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 關注
  • 316 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號