3

我正在用 jHipster 做一个实验。

我创建了两个由 DTO(mapstruct)支持的实体 A 和 B。它们之间存在多对多的关系。它们都与用户具有多对一的关系。

直到创建最后一个关系,一切正常。创建最后一个多对一关系后,出现以下错误:

[INFO] --- maven-processor-plugin:2.2.4:process (process) @ m2m ---
[ERROR] diagnostic: /Users/andy/jhipster-m2m/src/main/java/com/m2m/web/rest/mapper/AMapper.java:18: error: Ambiguous mapping methods found for mapping property "java.lang.Long userId" to com.m2m.domain.User: com.m2m.domain.User userFromId(java.lang.Long id), com.m2m.domain.User com.m2m.web.rest.mapper.BMapper.userFromId(java.lang.Long id).
A aDTOToA(ADTO aDTO);
  ^
[ERROR] error on execute: error during compilation

定义非常简单: 对于 A:

{
  "relationships": [
    {
        "relationshipId": 1,
        "relationshipName": "b",
        "otherEntityName": "b",
        "relationshipType": "many-to-many",
        "otherEntityField": "id",
        "ownerSide": true
    },
    {
        "relationshipId": 2,
        "relationshipName": "user",
        "otherEntityName": "user",
        "relationshipType": "many-to-one",
        "otherEntityField": "id"
    }
],
"fields": [
    {
        "fieldId": 1,
        "fieldName": "nameA",
        "fieldType": "String"
    }
],
"changelogDate": "20150909165353",
"dto": "mapstruct",
"pagination": "no"

}

对于 B:

{
"relationships": [
    {
        "relationshipId": 1,
        "relationshipName": "a",
        "otherEntityName": "a",
        "relationshipType": "many-to-many",
        "ownerSide": false,
        "otherEntityRelationshipName": "b"
    },
    {
        "relationshipId": 2,
        "relationshipName": "user",
        "otherEntityName": "user",
        "relationshipType": "many-to-one",
        "otherEntityField": "id"
    }
],
"fields": [
    {
        "fieldId": 1,
        "fieldName": "nameB",
        "fieldType": "String"
    }
],
"changelogDate": "20150909165433",
"dto": "mapstruct",
"pagination": "no"

}

我真的坚持这一点。很感谢任何形式的帮助!!

编辑:提供演示问题的 github 存储库https://github.com/andyverbunt/jhipster-m2m.git

4

2 回答 2

4

这似乎是上面评论中提到的错误。暂时您可以从其中一个映射器中删除该方法或在任何一个映射器中重命名该方法,我们将需要研究如何在 Jhipster 生成期间避免这种情况

这也可以通过使用 MapStruct 限定符来解决(请参阅参考文档中的基于限定符的选择)。

于 2015-09-13T11:14:30.760 回答
2

这似乎是一个错误,但不像上面提到的那样。JHipster 映射器生成器没有正确地将 @Mapper(..., users = {UserMapper.class}) 添加到 Mapper 类中。一年后我会回答这个问题,因为 JHipster 3.12.2 仍然是这种情况。

在您共享的源代码中,替换以下行:

@Mapper(componentModel = "spring", uses = {BMapper.class, })

有了这个:

@Mapper(componentModel = "spring", uses = {BMapper.class, UserMapper.class})
于 2017-01-30T15:26:07.297 回答