我正在做一個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