gpt4 book ai didi

jhipster - 如何修复不明确的映射方法

转载 作者:行者123 更新时间:2023-12-01 10:37:59 31 4
gpt4 key购买 nike

我正在用 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"

对于乙:

{
"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

最佳答案

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

这也可以通过使用 MapStruct 限定符来解决(请参阅引用文档中的 Selection based on Qualifiers)。

关于jhipster - 如何修复不明确的映射方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32486490/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com