I'm facing a problem for mapping entities. I actually extend all my entities why this class :
@MappedSuperclass
@Data
@EntityListeners(AuditingEntityListener.class)
@JsonIgnoreProperties(
value = {"logcreatedAt", "logupdatedAt"},
allowGetters = true
)
public abstract class AuditModel implements Serializable {
@Temporal(TemporalType.TIMESTAMP)
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
@Column(name = "log_created_at", nullable = false, updatable = false)
@CreatedDate
private Date logCreatedAt = new Date();
@Temporal(TemporalType.TIMESTAMP)
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
@Column(name = "log_updated_at", nullable = false)
@LastModifiedDate
private Date logUpdatedAt = new Date();
}
The problem, that i have is this one :
1) The destination property com.example.jpa.dto.HistoriqueDeploiementReadingDTO.setLog_updated_at() matches multiple source property hierarchies:
com.example.jpa.model.AuditModel.getLogUpdatedAt()
com.example.jpa.model.AuditModel.getLogCreatedAt()
com.example.jpa.model.HistoriqueDeploiement.getService()/com.example.jpa.model.AuditModel.getLogUpdatedAt()
com.example.jpa.model.HistoriqueDeploiement.getService()/com.example.jpa.model.AuditModel.getLogCreatedAt()
com.example.jpa.model.HistoriqueDeploiement.getNamespace()/com.example.jpa.model.AuditModel.getLogUpdatedAt()
com.example.jpa.model.HistoriqueDeploiement.getNamespace()/com.example.jpa.model.AuditModel.getLogCreatedAt()
I understand what's wrong for the mapper, but i don't find any solution for that... This stack doesn't help me at all : ModelMapper: matches multiple source property hierarchies
My mapper :
@Service
@Configuration
@Slf4j
public class MappingHistoriqueToDTO {
@Autowired
private HistoriqueDeploiementRepository historiqueDeploiementRepository;
@Autowired
private ModelMapper modelMapper;
@Bean
public ModelMapper modelMapper() {
ModelMapper modelMapper = new ModelMapper();
return modelMapper;
}
public List<HistoriqueDeploiementReadingDTO> findAllMapping() {
return ((List<HistoriqueDeploiement>) historiqueDeploiementRepository
.findAll())
.stream()
.map(this::convertToHistoriqueDeploiementReadingDTO)
.collect(Collectors.toList());
}
private HistoriqueDeploiementReadingDTO convertToHistoriqueDeploiementReadingDTO(HistoriqueDeploiement historiqueDeploiement) {
modelMapper.getConfiguration()
.setMatchingStrategy(MatchingStrategies.LOOSE);
HistoriqueDeploiementReadingDTO historiqueDeploiementReadingDTO = modelMapper
.map(historiqueDeploiement, HistoriqueDeploiementReadingDTO.class);
log.info("[Mapping] HistoriqueDeploiement -> HistoriqueDeploiementReadingDTO");
return historiqueDeploiementReadingDTO;
}
}
I would like that the mapper get the value of getLogUpdatedAt() from the historiquedeploiement entity and not from Namespace or Service.
Thanks !