【问题标题】:mapstruct does not set relationship properly on a bi-directional OneToManymapstruct 没有在双向 OneToMany 上正确设置关系
【发布时间】:2019-11-07 02:52:10
【问题描述】:

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

我粘贴了部分代码。我评论的那行是我手动添加的。 应该是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 jpa dto mapstruct


    【解决方案1】:
    猜你喜欢
    • 1970-01-01
    • 2012-03-27
    • 2013-05-09
    • 2015-02-14
    • 2019-10-12
    • 1970-01-01
    • 2018-11-29
    • 2023-04-09
    • 1970-01-01
    相关资源
    最近更新 更多