title: Mapstruct: how to map multiple fields from DTO to an object in Entity?
body: <p>i have this DTO:</p>
  
  <pre><code>@NoArgsConstructor
  public class DataDTO implements DTO {
  
      private static final long serialVersionUID = -5105904799152965475L;
  
      private Long deviceId;
  
      private OffsetDateTime generatedOn;
  
      public Long getDeviceId() {
          return deviceId;
      }
  
      public void setDeviceId(Long deviceId) {
          this.deviceId = deviceId;
      }
  
      public OffsetDateTime getGeneratedOn() {
          return generatedOn;
      }
  
      public void setGeneratedOn(OffsetDateTime generatedOn) {
          this.generatedOn = generatedOn;
      }
  }
  </code></pre>
  
  <p>i have this MongoDB document:</p>
  
  <pre><code>@Document(collection = "data")
  @EqualsAndHashCode
  public class DataDocument {
  
      private static final long serialVersionUID = 1772572723546311500L;
  
      @Id
      private IdByDeviceIdAndGeneratedOn id;
  
      public DataDocument() {
      }
  
      public IdByDeviceIdAndGeneratedOn getId() {
          return id;
      }
  
      public void setId(IdByDeviceIdAndGeneratedOn id) {
          this.id = id;
      }
  }
  </code></pre>
  
  <p>and this is the @Id class for MongoDB Document:</p>
  
  <pre><code>@EqualsAndHashCode
  @ToString
  public class IdByDeviceIdAndGeneratedOn {
  
      @Id
      private final Long deviceId;
  
      @Id
      @Field("generated_on")
      @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
      private final OffsetDateTime generatedOn;
  
      public IdByDeviceIdAndGeneratedOn(final Long deviceId, final OffsetDateTime         generatedOn) {
          this.deviceId = Objects.requireNonNull(deviceId);
          this.generatedOn = Objects.requireNonNull(generatedOn);
      }
  
      public Long getDeviceId() {
          return deviceId;
      }
  
      public OffsetDateTime getGeneratedOn() {
          return generatedOn;
      }
  }
  </code></pre>
  
  <p>this is the mapper for this Key class:</p>
  
  <pre><code>@Mapper(unmappedTargetPolicy = ReportingPolicy.ERROR, componentModel = "spring")
  public interface IdByDeviceIdAndGeneratedOnMapper {
  
      default IdByDeviceIdAndGeneratedOn toId(final Long deviceId, final   OffsetDateTime generatedOn) {
          return new IdByDeviceIdAndGeneratedOn(deviceId, generatedOn);
      }
      default Long getDeviceId(final IdByDeviceIdAndGeneratedOn id) {
          return id.getDeviceId();
      }
  
      default OffsetDateTime getGeneratedOn(final IdByDeviceIdAndGeneratedOn id) {
          return id.getGeneratedOn();
      }
  </code></pre>
  
  <p>and this is the @Mapper for DataDTO and DataDocument:</p>
  
  <pre><code>@Mapper( unmappedTargetPolicy = ReportingPolicy.ERROR,
      uses = {IdByDeviceIdAndGeneratedOnMapper.class,
              AccelerometerDocumentMapper.class,
              GpsDocumentMapper.class,
              GsmDocumentMapper.class
  })
  public interface DataDocumentMapper extends DocumentMapper&lt;DataDTO, DataDocument&gt; {
  
  }
  </code></pre>
  
  <p>this is the generic mapper:</p>
  
  <pre><code>/**
   * Contract for a generic dto to entity mapper.
   *
   * @param &lt;DTO&gt; - DTO source type parameter.
   * @param &lt;DOCUMENT&gt; - MongoDB Document destination type parameter.
   */
  
  public interface DocumentMapper&lt;DTO, DOCUMENT&gt; {
  
  DOCUMENT toDocument(DTO dto);
  
  DTO toDto(DOCUMENT document);
  
  }
  </code></pre>
  
  <p>Currently i'm receiving this errors:
  for MongoDB Data docment: </p>
  
  <blockquote>
    <p>Unmapped target property: "id".</p>
  </blockquote>
  
  <p>for DTO:</p>
  
  <blockquote>
    <p>Unmapped target properties: "deviceId, generatedOn".</p>
  </blockquote>
  
  <p>How to solve this errors without loosing immutability of Id class?</p>