Git Product home page Git Product logo

Comments (15)

chhsiao90 avatar chhsiao90 commented on July 22, 2024 1

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

from modelmapper.

jhalterman avatar jhalterman commented on July 22, 2024

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:

https://github.com/jhalterman/modelmapper/blob/13f2f7e9b663c69efe7531d16804d3e7b0876837/core/src/test/java/org/modelmapper/bugs/GH64.java

from modelmapper.

jedionmelbin avatar jedionmelbin commented on July 22, 2024

Dear, I have the same problem but with properties of duplicate type in each model I have properties with the same field.

  1. 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.

chhsiao90 avatar chhsiao90 commented on July 22, 2024

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.

dharaoza avatar dharaoza commented on July 22, 2024

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.

JuricaJaman avatar JuricaJaman commented on July 22, 2024

i am not sure anymore to use modelmapper at all in 2018 still this problem exists

from modelmapper.

mudassir047 avatar mudassir047 commented on July 22, 2024

mapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);

from modelmapper.

franco148 avatar franco148 commented on July 22, 2024

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.

franco148 avatar franco148 commented on July 22, 2024

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:

image

The result of the process is the following:

image

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();
}

image

Then I got the following:

image

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.

chhsiao90 avatar chhsiao90 commented on July 22, 2024

Thanks for the detailed information, I will investigate this bug.

from modelmapper.

chhsiao90 avatar chhsiao90 commented on July 22, 2024

hi @franco148 ,

One quick question: are below mappings that you expected?

createdById -> comment.id
resourceId -> comment.commentedResource.id

from modelmapper.

franco148 avatar franco148 commented on July 22, 2024

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.

image

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.

chhsiao90 avatar chhsiao90 commented on July 22, 2024

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.

franco148 avatar franco148 commented on July 22, 2024

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.

thelebdev avatar thelebdev commented on July 22, 2024

Anyone figure this out yet? 👁️

from modelmapper.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.