我正在做一个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
的定义很简单: 为:
{
"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"
}
我真的被困在这。 任何帮助非常感谢!
编辑:演示该问题https://github.com/andyverbunt/jhipster-m2m.git
为什么你有映射两种方法从ID用户?他们有什么不同? – Gunnar
嗨Gunnar,感谢您的反馈。 AFAIK,没有两种方法将id映射到用户,至少不在同一个对象中。实体A需要知道它的所有者,B也是一样,但它们是不同的对象。 我会在github上发布示例并编辑帖子,以便友好的助手可以看看它。 –
您是否手动更改了任何内容?如果看起来不像我们使用mapstruct生成的bug。当mapstruct试图将userID从DTO映射到User中的id时,它看到两个方法'userFromId'正在执行该功能,一个在AMapper中,另一个在BMapper中 – Deepu