i have an object school that has an object person, persons are already saved in a data base and when i save a school object i give it a person id
so in the class school i have an attribute person of type Person, and in SchoolDTO i have an attribute personId of type Long
@Mapper(componentModel = "spring", uses = { PersonMapper.class })
public interface SchoolMapper extends EntityMapper<SchoolDTO, School>{
@Mapping(source = "personId", target = "person")
School toEntity(SchoolDTO schoolDTO);
}
School school = schoolMapper.toEntity(schoolDTO);
log.info(school.getPerson());
public interface EntityMapper <D, E> {
E toEntity(D dto);
D toDto(E entity);
List <E> toEntity(List<D> dtoList);
List <D> toDto(List<E> entityList);
}
@Mapper(componentModel = "spring", uses = {})
public interface PersonMapper extends EntityMapper<PersonDTO, Person> {
default Person fromId(Long id) {
if (id == null) {
return null;
}
Person person= new Person();
person.setId(id);
return person;
}
}
the problem here when i display the person it shows me the id with their value and the other attribute null