If I add a mapping for Hibernate Entity to a DTO class convertion everything works well because the model mapper doesn't receive a proxied class.
But if the mapper receive a collection of objects that contain that Entity class, the Model mapper receives the proxied class. The result is that modelmapper doesn't match the type inside the configuration and misses the correct mapper.
Looking at the deProxy method I see that isProxy doesn't detect any HibernateProxy class.
Is this a bug or I need to change something in my code?
// On the mapper init
modelMapper.createTypeMap(TypeOfRightEntity.class, TypeOfRight.class)
.addMappings(mapper -> mapper.using(ctx -> ctx.getSource() == null ? null : ((TypeOfRightEntity)ctx.getSource()).getId())
.map(TypeOfRightEntity::getRightOfAggregation, TypeOfRight::setRightOfAggregation));
modelMapper.getConfiguration()
.setMatchingStrategy(MatchingStrategies.STRICT).setFieldMatchingEnabled(true);
// On the dto class (Informe83 contains a field wity the TypeOfRightEntity type
Page<Informe83Entity> p = someFunctionThatGetDataFromHibernate()
Type listType = new TypeToken<List<Informe83>>() { }.getType();
return new PageImpl<>(modelMapper.map(p.getContent(), listType), PageRequest.of(page, size), p.getTotalElements());
The strange thing is that if I use this (manual) conversion everything works fine!
List<Informe83> test = new ArrayList<>();
for (Informe83Entity item: p.getContent()) {
test.add(modelMapper.map(item, Informe83.class));
}
If I add a mapping for Hibernate Entity to a DTO class convertion everything works well because the model mapper doesn't receive a proxied class.
But if the mapper receive a collection of objects that contain that Entity class, the Model mapper receives the proxied class. The result is that modelmapper doesn't match the type inside the configuration and misses the correct mapper.
Example: it.itsright.commondata.dal.entity.TypeOfRightEntity$HibernateProxy$cbqs6eEb
Looking at the deProxy method I see that isProxy doesn't detect any HibernateProxy class.
Is this a bug or I need to change something in my code?
The strange thing is that if I use this (manual) conversion everything works fine!