Comments (15)
Is mapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
working for you?
And could you please provide more detail about your source/destination class. Thanks.
from modelmapper.
With just the example code you posted there shouldn't be a circular mapping problem. I tried to reproduce this in a simple test, but the test is passing fine right now. Have a look and let me know if I missed something:
from modelmapper.
Dear, I have the same problem but with properties of duplicate type in each model I have properties with the same field.
-
The destination property com.infiniteskills.domain.DTO.DocumentoIdentidadDTO.setDocumentoIdentidadId() matches multiple source property hierarchies:
com.infiniteskills.domain.model.DocumentoIdentidad.getUsuarioCreacionId()
com.infiniteskills.domain.model.DocumentoIdentidad.getUsuarioModificaId()
from modelmapper.
Thanks for the report.
Could you provide what it look like of the source class and the destination class?
Or maybe you can provide a minimum reproducer if you cannot provide the source class and destination class.
That will help us to solve your issue, thanks!
from modelmapper.
I have the same problem can you please help me to solve.
The destination property com.measureone.vo.OrgApplicationPerson.setPersonParty()/com.measureone.vo.Party.setModifiedByPersonParty() matches multiple source property hierarchies:
com.measureone.dto.UserDTO.getModifiedByPersonPartyName()
com.measureone.dto.UserDTO.getModifiedByPersonPartyId()
from modelmapper.
i am not sure anymore to use modelmapper at all in 2018 still this problem exists
from modelmapper.
mapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
from modelmapper.
Still the problem exists. As the example provide by @ACodeFarmer I have my Jpa Entities with bidirectional relationships. So I am getting the following exception.
The destination property com..BaseEntity.setId() matches multiple source property hierarchies.........
The version of org.modelmapper that I am using is: 2.0.0
from modelmapper.
Sure! I have the following:
My domain model:
@Data
@MappedSuperclass
public abstract class BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
private Long id;
private LocalDateTime createdAt;
private LocalDateTime updatedAt;
@Column(nullable = false)
private Boolean isDeleted;
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "FK_CreatedBy")
private Participant createdBy;
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "FK_UpdatedBy")
private Participant updatedBy;
}
@EqualsAndHashCode(callSuper = true)
@Data
@Entity
public class Comment extends BaseEntity {
@Column(nullable = false)
private Integer messagesAmount;
@OneToOne(optional = false)
@JoinColumn(name = "FK_Resource")
private Resource commentedResource;
.....
}
@Data
@Entity
public class Resource {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
private Long id;
@Enumerated(EnumType.STRING)
private ResourceType type;
@OneToOne(mappedBy = "commentedResource")
private Comment comment;
......
}
My DTO:
@Getter
@Setter
public class CreateCommentDto {
private Long commentedResourceId;
private Long createdById;
@JsonIgnore
private LocalDateTime createdAt = LocalDateTime.now();
@JsonIgnore
private LocalDateTime updatedAt = LocalDateTime.now();
}
Calling my RestController from postman as following:
The result of the process is the following:
The example code where I am using the modelmapper is (I tested with other modelmapper configurations as well):
@Override
public ResponseEntity<Comment> create(@RequestBody final CreateCommentDto commentDto) {
//modelMapper.getConfiguration().setFieldMatchingEnabled(true);
//modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
Comment converted = modelMapper.map(commentDto, Comment.class);
.....
}
Then I was also trying changing the name of the properties, as following:
@Getter
@Setter
public class CreateCommentDto {
private Long resourceId;
private Long createdById;
@JsonIgnore
private LocalDateTime createdAt = LocalDateTime.now();
@JsonIgnore
private LocalDateTime updatedAt = LocalDateTime.now();
}
Then I got the following:
Maybe something I am not implementing it in the right way, could you please help me to realize the issue?
Thanks in advance!
from modelmapper.
Thanks for the detailed information, I will investigate this bug.
from modelmapper.
hi @franco148 ,
One quick question: are below mappings that you expected?
createdById -> comment.id
resourceId -> comment.commentedResource.id
from modelmapper.
Sorry, I have not copied all the entities.
createdById : is the reference to a Participant entity. So, it would be comment.createdBy.Id
resourceId: yes, it refereces to comment.commentedResource.id
Here the missing entity.
@Data
@Entity
public class Participant {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
private Long id;
@OneToMany(mappedBy = "sharedBy")
private Set<ShareAction> shared;
@OneToMany(mappedBy = "sharedWith")
private Set<ShareAction> sharedWithMe;
@OneToMany(mappedBy = "createdBy")
private Set<Message> messages;
}
The diagram for these entities would be something like this.
So, in the controller I am calling a creation of a comment, which has a reference to a Recourse ID and Participant ID.
Hope that helps.
from modelmapper.
hi @franco148 ,
Our matching strategy is not smart as you think, it has some rules, please refer matching-strategies for detail.
For mappings that our matching strategy can't support correctly, please try our property-mapping for customize mappings.
And it's weird that comment.createdAt is a LocalDateTime, I don't think it has a property named id.
from modelmapper.
Hi @chhsiao90
Sorry it was my mistake in the explanation, I have already updated that comment. comment.createdBy was the correct relation.
Thank you for your support. I will take a look at the resources you are suggesting me.
from modelmapper.
Anyone figure this out yet? 👁️
from modelmapper.
Related Issues (20)
- How to skip not loaded Lazy fields?
- Test fails after upgrading from 3.1.0 to 3.1.1
- Java 21 support HOT 18
- Support of Java Module System
- Custom mapping in nested objects HOT 4
- Skip field of generic class HOT 1
- Mapping Source object to Destination object
- Mapping nested generic object with generic HOT 1
- Use specific converter for one field
- Model Mapper does not map values correctly (Intermittent - once in a few tries)
- Model Mapper Low performance
- Jackson Module: @JsonTypeInfo support for automatically handling inheritance HOT 1
- ModelMapper fails to map nested entity user field HOT 1
- When condition does not work for null-field
- How to ignore mapping errors HOT 1
- ModelMapper not working with nested generics
- modelmapper Hot deployment HOT 1
- How to Throw Validation exception when Source has a property that cannot be mapped to Destination HOT 1
- Test dependencies upgrade
- Basic Mapping doesn't work as expected.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from modelmapper.