1

Since I upgrade my project from jhipster 5.8.2 to jhipster 6.5.1, I have a lot of warnings with Mapper.

I would treat properly this warning and not addd this property in all Mapper :

(unmappedTargetPolicy = ReportingPolicy.IGNORE)

For example I have this error :

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

In my object Permission, I have :

@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;
}

And the 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;
}

And the Mapper :

@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);

The ligne with "ignore = true" does not work.

Have you an idea please ?

Gaël Marziou
  • 16,028
  • 4
  • 38
  • 49
user1450740
  • 731
  • 10
  • 26
  • Does this answer your question? [MapStruct ignore automatically unmapped properties](https://stackoverflow.com/questions/36788642/mapstruct-ignore-automatically-unmapped-properties) – admlz635 Dec 13 '19 at 17:28

1 Answers1

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

You can define the property on each mapper or use a shared mapper config. The solution to your problem is defined in the below link

Ignore unmapped properties

Kaushik
  • 46
  • 2