matches multiple source property hierarchies problem

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Reactions:1
  • Comments:15 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
chhsiao90commented, Jun 1, 2018

Is mapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT); working for you? And could you please provide more detail about your source/destination class. Thanks.

0reactions
thelebdevcommented, Sep 16, 2022

Anyone figure this out yet? 👁️

Read more comments on GitHub >

github_iconTop Results From Across the Web

ModelMapper: matches multiple source property hierarchies
This resolved my problem: modelMapper.getConfiguration().setAmbiguityIgnored(true);.
Read more >
destination property setId() matches multiple source ... - GitHub
I am using ModelMapper with all default settings. I tried STRICT and the problem goes away, but that causes other problems, so I...
Read more >
Configuration - ModelMapper
The Loose matching strategy allows for source properties to be loosely matched to destination properties by requiring that only the last destination property...
Read more >
the destination property matches multiple source property ...
Multiple PropertyMaps may be added for the same source and destination types, so long as only one mapping is defined for each destination...
Read more >
ConfigurationException: ModelMapper configuration errors:
I'm trying to use ModelMapper in a grails project. Its works and I need to skip certain field while mapping from Domain to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found