New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
matches multiple source property hierarchies problem #64
Comments
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: |
Dear, I have the same problem but with properties of duplicate type in each model I have properties with the same field.
|
Thanks for the report. |
I have the same problem can you please help me to solve.
|
i am not sure anymore to use modelmapper at all in 2018 still this problem exists |
mapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT); |
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 |
Is |
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! |
Thanks for the detailed information, I will investigate this bug. |
hi @franco148 , One quick question: are below mappings that you expected?
|
Sorry, I have not copied all the entities. createdById : is the reference to a Participant entity. So, it would be comment.createdBy.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. |
hi @franco148 , And it's weird that comment.createdAt is a LocalDateTime, I don't think it has a property named id. |
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. |
Anyone figure this out yet? 👁️ |
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.
then, I've tried to mapping DTO object instance to domain object instance.
this code returns error
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.
The text was updated successfully, but these errors were encountered: