我正在用jHipster做一个实验。
我创建了两个由DTO支持的实体A和B(mapstruct)。 他们之间有多对多的关系。 他们俩也与用户建立了多对一的关系。
直到创建最后一个关系,一切正常。 创建最后的多对一关系后,我收到以下错误:
[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 repo https://github.com/andyverbunt/jhipster-m2m.git
答案 0 :(得分:4)
这似乎是上面评论中提到的错误。暂时你可以从一个mapper中删除方法,或者在任何一个mapper中重命名方法,我们需要研究如何在Jhipster生成过程中避免这种情况
这也可以通过使用MapStruct限定符来修复(参见参考文档中的Selection based on Qualifiers)。
答案 1 :(得分:1)
这似乎是一个错误,但不像上面提到的那样。 JHipster映射器生成器未正确地将@Mapper(...,users = {UserMapper.class})添加到Mapper类。我在一年后回答这个问题,因为JHipster 3.12.2仍然如此。
在您分享的来源中,替换以下行:
@Mapper(componentModel = "spring", uses = {BMapper.class, })
有了这个:
@Mapper(componentModel = "spring", uses = {BMapper.class, UserMapper.class})