英文:
Same data type, but can't have the same name?
问题
一些我们的数据实体有多个具有相同数据类型的子实体集合。以下是一个JDL文件来说明这种关系。
entity Parent {
name String
headOfHousehold Boolean
}
entity Child {
name String
}
relationship ManyToOne {
Child{parent(name)} to Parent{boys}
Child{parent(name)} to Parent{girls}
}
当我运行导入命令时,我收到以下错误消息:
Error: Error at entity Parent: relationship name is not synchronized {
"otherEntityName": "child",
"otherEntityRelationshipName": "parent",
"relationshipName": "girls",
"relationshipType": "one-to-many",
"otherEntity": "[Child Entity]",
"otherEntityField": "id",
"ownerSide": false,
"collection": true,
"otherSideReferenceExists": false,
"otherEntityIsEmbedded": false
} with {
"otherEntityField": "name",
"otherEntityName": "parent",
"otherEntityRelationshipName": "boys",
"relationshipName": "parent",
"relationshipType": "many-to-one",
"otherEntity": "[Parent Entity]"
}
我不知道消息中的"synchronized"是什么意思。
在重命名Child实体后,导入过程将不会出现错误。
entity Parent {
name String
headOfHousehold Boolean
}
entity Boy {
name String
}
entity Girl {
name String
}
relationship ManyToOne {
Boy{parent(name)} to Parent{boys}
Girl{parent(name)} to Parent{girls}
}
在JPA中,以下实体类结构是正确的。
@Entity
public class Parent {
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = "parent_id")
private Collection<Child> boys;
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = "parent_id")
private Collection<Child> girls;
}
@Entity
public class Child {
// ...
}
为什么JHipster不适用于相同的实体类结构?
英文:
Some of our data entities have more than one collection of child entities with the same data type. Here is a JDL file to illustrate the relationship.
entity Parent {
name String
headOfHousehold Boolean
}
entity Child {
name String
}
relationship ManyToOne {
Child{parent(name)} to Parent{boys}
Child{parent(name)} to Parent{girls}
}
When I run the import command, I get the following error:
Error: Error at entity Parent: relationship name is not synchronized {
"otherEntityName": "child",
"otherEntityRelationshipName": "parent",
"relationshipName": "girls",
"relationshipType": "one-to-many",
"otherEntity": "[Child Entity]",
"otherEntityField": "id",
"ownerSide": false,
"collection": true,
"otherSideReferenceExists": false,
"otherEntityIsEmbedded": false
} with {
"otherEntityField": "name",
"otherEntityName": "parent",
"otherEntityRelationshipName": "boys",
"relationshipName": "parent",
"relationshipType": "many-to-one",
"otherEntity": "[Parent Entity]"
}
I don't know what "synchronized" means in the message.
After renaming the Child entity,
entity Parent {
name String
headOfHousehold Boolean
}
entity Boy {
name String
}
entity Girl {
name String
}
relationship ManyToOne {
Boy{parent(name)} to Parent{boys}
Girl{parent(name)} to Parent{girls}
}
The import process will work without the error.
In JPA, the following entity class structure is correct.
@Entity
public class Parent {
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = "parent_id")
private Collection<Child> boys;
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = "parent_id")
private Collection<Child> girls;
}
@Entity
public class Child {
// ...
}
Why JHipster doesn't work for the same entity class structure?
答案1
得分: 1
问题不在于重复的类型,而在于重复的名称。
在两种情况下,您都将关系命名为 parent
,它们都在同一个 Child 类中。 使用 boysParent
和 girlsParent
将会起作用:
relationship ManyToOne {
Child{boysParent(name)} to Parent{boys}
Child{girlsParent(name)} to Parent{girls}
}
请查看文档:https://www.jhipster.tech/managing-relationships/#two-one-to-many-relationships-on-the-same-two-entities
英文:
The issue isn't about duplicating types, but duplicating names.
You named the relationship parent
in both cases and they are in the same Child class. Using boysParent
and girlsParent
would have worked:
relationship ManyToOne {
Child{boysParent(name)} to Parent{boys}
Child{girlsParent(name)} to Parent{girls}
}
Have a look at the documentation: https://www.jhipster.tech/managing-relationships/#two-one-to-many-relationships-on-the-same-two-entities
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论