1

我在实体上有多个标记接口和 MappedSuperclass-es,我想创建一个共享配置,以忽略一些实体特定的目标。

示例接口和类:

public interface LongPrimaryKey extends Serializable

public abstract class FeatureBaseEntity extends BaseEntity

public class MyEntity extends FeatureBaseEntity implements LongPrimaryKey

我在 MapperConfig 界面中执行以下操作:

@MapperConfig(
    unmappedTargetPolicy = ReportingPolicy.ERROR, 
    mappingInheritanceStrategy = MappingInheritanceStrategy.AUTO_INHERIT_FROM_CONFIG
)
public interface CentralConfig {

    @Mapping(target = "id", ignore = true)
    LongPrimaryKey toLongPrimaryKey(Model model);

    @Mappings({
        @Mapping(target = "createdAt", ignore = true),
        @Mapping(target = "modifiedAt", ignore = true)
    })
    BaseEntity toBaseEntity(Model model);

    @Mappings({
        @Mapping(target = "createdAt", ignore = true),
        @Mapping(target = "modifiedAt", ignore = true),
        @Mapping(target = "id", ignore = true)
    })
    <T extends BaseEntity & LongPrimaryKey> T toBaseEntityLongPrimaryKey(Model model);

}

@Mapper(config = CentralConfig.class)
public interface MyEntityMapper {

    @Mappings({
        @Mapping(...)
    })
    @InheritConfiguration(name = "toBaseEntityLongPrimaryKey")
    MyEntity toMyEntity(MyFeatureModel myFeatureModel, @MappingTarget MyEntity entity);
}

这抛出以下内容:

[DEBUG] diagnostic MyEntityMapper.java:28: error: None of the candidates toLongPrimaryKey(), toBaseEntity() matches given name: "toBaseEntityLongPrimaryKey".
    @InheritConfiguration(name = "toBaseEntityLongPrimaryKey")
    ^
[DEBUG] diagnostic MyEntityMapper.java:29: error: More than one configuration prototype method is applicable.
Use @InheritConfiguration to select one of them explicitly: LongPrimaryKey toLongPrimaryKey(Model model), BaseEntity toBaseEntity(Model model).
    MyEntity toMyEntity(MyFeatureModel myFeatureModel, @MappingTarget MyEntity entity);

此功能尚未涵盖,还是我遗漏了什么?

4

1 回答 1

0

<T>是的,这是与您toBaseEntityLongPrimaryKey()方法中的类型变量有关的问题。它在例如引用该toBaseEntity()方法时起作用。

请您在我们的跟踪器中为这个问题打开一个问题,好吗?谢谢!

于 2015-12-11T22:20:16.507 回答