相关疑难解决方法(0)

使用maven-processor-plugin生成JPA元模型文件 - 重新生成的便捷方式是什么?

我正在尝试使用maven-processor-plugin生成JPA元模型java文件,并设置我的pom.xml如下所示.

<plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
            <source>1.8</source>
            <target>1.8</target>
            <compilerArgument>-proc:none</compilerArgument>
        </configuration>
    </plugin>
    <plugin>
        <groupId>org.bsc.maven</groupId>
        <artifactId>maven-processor-plugin</artifactId>
        <executions>
            <execution>
                <id>process</id>
                <goals>
                    <goal>process</goal>
                </goals>
                <phase>generate-sources</phase>
                <configuration>
                    <!-- source output directory -->
                    <outputDirectory>${basedir}/src/main/java</outputDirectory>
                    <processors>
                        <processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>
                    </processors>
                    <overwrite>true</overwrite>
                </configuration>
            </execution>
        </executions>
    </plugin>
Run Code Online (Sandbox Code Playgroud)

实际上,我想生成元模型文件(Entity_.java)到相应实体(Entity.java)的相同包中.因此,我在插件中设置outputDirectory为

<outputDirectory>${basedir}/src/main/java</outputDirectory>
Run Code Online (Sandbox Code Playgroud)

第一次运行是好的,但是从以后执行元模型java文件重新生成时,插件总是会出现关于文件复制的错误.

我的问题是 - 有没有办法配置插件,以便它可以在重新生成过程中覆盖现有的文件?

事实上,要解决

  1. 我必须在重新生成之前删除所有生成的文件.
  2. 我可以将outputDirectory指向/ target中的不同文件夹,每次Maven运行时此位置都将保持干净,但这会导致在重新生成后手动将生成的元模型文件复制到源文件夹以进行更新.

这两个都非常不方便,我希望你们能给我一个合适的解决方案.

hibernate jpa maven

7
推荐指数
3
解决办法
8679
查看次数

将 WHERE IN 子句添加到 JPA 规范

我正在尝试实现受 IN 子句限制的搜索功能:

我想实现带有过滤器限制的搜索实现:

    @GetMapping("find")
    public Page<MerchantUserDTO> getAllBySpecification(
            @And({
                @Spec(path = "name", spec = LikeIgnoreCase.class),
                @Spec(path = "login", spec = LikeIgnoreCase.class),
                @Spec(path = "email", spec = LikeIgnoreCase.class),
            }) Specification<Users> specification,
            @SortDefault(sort = "login", direction = Sort.Direction.DESC) Pageable pageable
    ) {        
        return merchantUserService.getAllBySpecification(specification, pageable)
                .map(g -> MerchantUserDTO.builder()                   
                        .id(g.getId())
                        .login(g.getLogin())                        
                        .build()
                );
    }

    @Override
    public Page<Users> getAllBySpecification(Specification<Users> specification, Pageable pageable) {
        return dao.findAllByTypeIn(specification, pageable, "MerchantUser");
    }
Run Code Online (Sandbox Code Playgroud)

存储库:

@Repository
public interface MerchantUserRepository extends JpaRepository<Users, Integer>, JpaSpecificationExecutor<Users> {

    Page<Users> findAllByTypeIn(Pageable page, String... types);

    Page<Users> …
Run Code Online (Sandbox Code Playgroud)

jpa jpa-2.0 spring-data-jpa jpa-2.1 spring-boot

6
推荐指数
1
解决办法
1万
查看次数

标签 统计

jpa ×2

hibernate ×1

jpa-2.0 ×1

jpa-2.1 ×1

maven ×1

spring-boot ×1

spring-data-jpa ×1