modelmapper: matches multiple source property hierarchies problem
Hi, I’m using JPA(with Hibernate) and wish to convert some composite domain to view layer, So I’m using ModelMapper also.
At first, I defined some domain and DTO classes.
@Entity
public class User {
...
@Id
String id;
@OneToOne
Preference preference;
...
}
@Entity
public class Preference {
...
@Id
String id;
@OneToOne
User user;
BigDecimal money;
...
}
public class UserDto {
...
String id;
BigDecimal preferenceMoney;
...
}
then, I’ve tried to mapping DTO object instance to domain object instance.
UserDto userDto = new UserDto();
userDto.setPreferenceMoney(1000.0);
mapper.map(userDto, User.class);
this code returns error
1) The destination property User.setPreference()/Preference.setUser() matches multiple source property hierarchies:
Skipping to set user to Preference class suppress this error, but when saving data to persist returned exception that preference object instance couldn’t get user property. 😦
Is this an another case of circular reference problem? I’ve dig circular reference test cases, but I can’t find a solution.
About this issue
- Original URL
- State: closed
- Created 11 years ago
- Reactions: 1
- Comments: 15 (6 by maintainers)
Is
mapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
working for you? And could you please provide more detail about your source/destination class. Thanks.