如何在 Mapper 中删除警告 Unmapped target 属性?

How delete warning Unmapped target property in Mapper?

自从我将项目从 jhipster 5.8.2 升级到 jhipster 6.5.1 后,Mapper 出现了很多警告。

我会妥善处理这个警告,而不是在所有 Mapper 中添加这个 属性 :

(unmappedTargetPolicy = ReportingPolicy.IGNORE)

例如我有这个错误:

service\mapper\PermissionMapper.java:25: warning: Unmapped target property: "removeEntite".
Permission toEntity(PermissionDTO permissionDTO);

在我的对象许可中,我有:

@Entity
@Table(name = "permission")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Permission implements Serializable {

private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@ManyToOne
private Profil profil;

@ManyToOne
private User user;

@ManyToMany
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@JoinTable(name = "permission_entite",
           joinColumns = @JoinColumn(name = "permissions_id", referencedColumnName = "id"),
           inverseJoinColumns = @JoinColumn(name = "entites_id", referencedColumnName = "id"))
private Set<Entite> entites = new HashSet<>();

.... 
 public Set<Entite> getEntites() {
    return entites;
}

public Permission entites(Set<Entite> entites) {
    this.entites = entites;
    return this;
}

public Permission addEntite(Entite entite) {
    this.entites.add(entite);
    entite.getPermissions().add(this);
    return this;
}

public Permission removeEntite(Entite entite) {
    this.entites.remove(entite);
    entite.getPermissions().remove(this);
    return this;
}

public void setEntites(Set<Entite> entites) {
    this.entites = entites;
}

和 PermissionDTO :

public class PermissionDTO implements Serializable {

private Long id;

private Long profilId;

private String profilNom;

private Long userId;

private String userLogin;

private Set<EntiteDTO> entites = new HashSet<>();

... 

public Set<EntiteDTO> getEntites() {
    return entites;
}

public void setEntites(Set<EntiteDTO> entites) {
    this.entites = entites;
}

映射器:

@Mapper(componentModel = "spring", uses = {ProfilMapper.class, UserMapper.class, EntiteMapper.class, })
public interface PermissionMapper extends EntityMapper <PermissionDTO, Permission> {

@Mapping(source = "profil.id", target = "profilId")
@Mapping(source = "profil.nom", target = "profilNom")

@Mapping(source = "user.id", target = "userId")
@Mapping(source = "user.login", target = "userLogin")
PermissionDTO toDto(Permission permission);

@Mapping(source = "profilId", target = "profil")

@Mapping(source = "userId", target = "user")
@Mapping(target = "entites", ignore = true)
Permission toEntity(PermissionDTO permissionDTO);

"ignore = true" 的行不工作。

你有什么想法吗?

@Mapper(componentModel = "spring", uses = {ProfilMapper.class, UserMapper.class, EntiteMapper.class, }, unmappedTargetPolicy = ReportingPolicy.IGNORE)

您可以在每个映射器上定义 属性 或使用共享映射器配置。 您的问题的解决方案定义在下面 link

Ignore unmapped properties