java - mapstruct 未在双向 OneToMany 上正确设置关系

标签 java jpa dto mapstruct

我有一个 JPA 一对多双向关联。在我的代码中,我设置了双方的关系。但生成的映射结构代码似乎没有正确设置关系。我的意思是它设置在一侧。

我粘贴了部分代码。我评论的行是我手动添加的。 它应该是由mapstruct生成的

    derivativeFuture.setDerivativeExecutions( derivativeExecutionDTOSetToDerivativeExecutionSet( derivativeDTO.getDerivativeExecutions() ) );
    //derivativeFuture.getDerivativeExecutions().forEach(derivativeExecution -> { derivativeExecution.setDerivative(derivativeFuture); });


protected Set<DerivativeExecution> derivativeExecutionDTOSetToDerivativeExecutionSet(Set<DerivativeExecutionDTO> set) {
    if ( set == null ) {
        return null;
    }

    Set<DerivativeExecution> set1 = new HashSet<DerivativeExecution>( Math.max( (int) ( set.size() / .75f ) + 1, 16 ) );
    for ( DerivativeExecutionDTO derivativeExecutionDTO : set ) {
        set1.add( derivativeExecutionDTOToDerivativeExecution( derivativeExecutionDTO ) );
    }

    return set1;
}


protected DerivativeExecution derivativeExecutionDTOToDerivativeExecution(DerivativeExecutionDTO derivativeExecutionDTO) {
    if ( derivativeExecutionDTO == null ) {
        return null;
    }

    DerivativeExecution derivativeExecution = new DerivativeExecution();

    derivativeExecution.setPhysicalQuantity( derivativeExecutionDTO.getPhysicalQuantity() );
    derivativeExecution.setExchangeQuantity( derivativeExecutionDTO.getExchangeQuantity() );
    derivativeExecution.setPurchaseSaleIndicator( derivativeExecutionDTO.getPurchaseSaleIndicator() );
    derivativeExecution.setQuotePricingStartDate( derivativeExecutionDTO.getQuotePricingStartDate() );
    derivativeExecution.setQuotePricingEndDate( derivativeExecutionDTO.getQuotePricingEndDate() );
    derivativeExecution.setContractExecutionId( derivativeExecutionDTO.getContractExecutionId() );

    return derivativeExecution;
}

最佳答案

关于java - mapstruct 未在双向 OneToMany 上正确设置关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56751122/

相关文章:

jpa - 为什么在查询期间会调用 JPA @PreUpdate-annotated 方法?

java - JPA Hibernate - 数据库和注释中的级联删除

java - Mapstruct 如何将实体映射到字符串以及字符串映射到相应的实体

wcf - 在 SOA 应用程序中使用 DTO 的最佳方式是什么?

java - 从领域对象构建DTO的设计

java - 包装第三方库时包装异常

java - 我如何比较 BigInteger 的值以用作循环中的条件?

java - 无法从资源中读取文件

java - 如何使用 JavaFX 和 scenebulider 配置 IntelliJ IDEA?

database - Java EE/JPA : Improve query performance - store UUID as binary