相同的数据类型,但不能有相同的名称?

huangapple go评论49阅读模式
英文:

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 {
    &quot;otherEntityName&quot;: &quot;child&quot;,
    &quot;otherEntityRelationshipName&quot;: &quot;parent&quot;,
    &quot;relationshipName&quot;: &quot;girls&quot;,
    &quot;relationshipType&quot;: &quot;one-to-many&quot;,
    &quot;otherEntity&quot;: &quot;[Child Entity]&quot;,
    &quot;otherEntityField&quot;: &quot;id&quot;,
    &quot;ownerSide&quot;: false,
    &quot;collection&quot;: true,
    &quot;otherSideReferenceExists&quot;: false,
    &quot;otherEntityIsEmbedded&quot;: false
} with {
    &quot;otherEntityField&quot;: &quot;name&quot;,
    &quot;otherEntityName&quot;: &quot;parent&quot;,
    &quot;otherEntityRelationshipName&quot;: &quot;boys&quot;,
    &quot;relationshipName&quot;: &quot;parent&quot;,
    &quot;relationshipType&quot;: &quot;many-to-one&quot;,
    &quot;otherEntity&quot;: &quot;[Parent Entity]&quot;
}

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 = &quot;parent_id&quot;)
    private Collection&lt;Child&gt; boys;

    @OneToMany(cascade = CascadeType.ALL)
    @JoinColumn(name = &quot;parent_id&quot;)
    private Collection&lt;Child&gt; girls;
}

@Entity
public class Child {
    // ...
}

Why JHipster doesn't work for the same entity class structure?

答案1

得分: 1

问题不在于重复的类型,而在于重复的名称。
在两种情况下,您都将关系命名为 parent,它们都在同一个 Child 类中。 使用 boysParentgirlsParent 将会起作用:

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

huangapple
  • 本文由 发表于 2023年7月18日 03:08:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/76707435.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定