具有继承性的Mapstruct映射器

问题描述 投票:0回答:2

我有一个 BaseEntity,它有一个名为 Customer 的孩子 当我像这样制作映射器时:

@Mapper(componentModel = "spring")
public interface CustomerMapper {

    Customer toEntity(CustomerDTO model);

    List<Customer> toEntityList(List<CustomerDTO> models);

    CustomerDTO toModel(Customer entity);

    List<CustomerDTO> toModelList(List<Customer> entities);

}

BaseEntity 字段不会由 Mapstruct 自动映射。你能告诉我该怎么做吗?

编辑:

基础实体:

@MappedSuperclass
@Data
@EntityListeners(AuditingEntityListener.class)
public abstract class BaseEntity implements Serializable {

    private static final long serialVersionUID = 698399842496839094L;

    @EqualsAndHashCode.Include
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
    @SequenceGenerator(name = "sequenceGenerator")
    protected Long id;


    @Column(nullable = false, length = 36)
    protected String uuid;
}

顾客:

@EqualsAndHashCode(callSuper = true)
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@Data
publi class Customer extends BaseEntity {

    private static final long serialVersionUID = 7054669140361044232L;


    @Column(length = 50, unique = true, nullable = false)
    private String login;


    @Column(name = "password_hash", nullable = false, length = 60)
    private String password;
}
java spring mapstruct
2个回答
0
投票

我创建了一个示例存储库来证明一切都按预期工作。请将其与您的代码进行比较,看看有什么不同。


0
投票

我遇到了同样的错误。现在修好了吗?

© www.soinside.com 2019 - 2024. All rights reserved.