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

时间:2019-06-25 09:43:59

标签: java jpa dto mapstruct

我有一个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;
}