如何关联Jhipster JDL中的两个实体?

如何关联Jhipster JDL中的两个实体?,jhipster,Jhipster,假设您有一个Jhipster应用程序,该应用程序有一个配置文件,需要注册哪些配置文件遵循其他配置文件,并具有两个属性:一个用于跟随的用户(用户配置文件),另一个用于跟随的用户(跟随配置文件)。比如: entity Profile { creationDate Instant required } entity Follows { creationDate Instant } relationship OneToMany { Profile{follows(user)} t

假设您有一个Jhipster应用程序,该应用程序有一个配置文件,需要注册哪些配置文件遵循其他配置文件,并具有两个属性:一个用于跟随的用户(用户配置文件),另一个用于跟随的用户(跟随配置文件)。比如:

entity Profile {
    creationDate Instant required
}

entity Follows {
  creationDate Instant
}

relationship OneToMany {
    Profile{follows(user)} to Follows{profile(id)}
    Profile{follows(followed)} to Follows{profile(id)}
}
问题是Follows.java有两个相同的atribute,即使名称不同follow(user)和follow(follow):

。。。而不是

@ManyToOne
private Profile user;

@ManyToOne
private Profile followed;

谢谢。

您对两个关系使用相同的关系名称,但每个关系名称必须不同,否则字段会冲突

relationship (OneToMany | ManyToOne | OneToOne | ManyToMany) {
  <from entity>[{<relationship name>[(<display field>)]}] to <to entity>[{<relationship name>[(<display field>)]}]
}

两个关系使用相同的关系名称,但每个关系名称必须不同,否则字段会冲突

relationship (OneToMany | ManyToOne | OneToOne | ManyToMany) {
  <from entity>[{<relationship name>[(<display field>)]}] to <to entity>[{<relationship name>[(<display field>)]}]
}

您可以拥有这些实体

entity NmsPatient {
photo ImageBlob
}

entity NmsRoom {
code String required,
name String required
}

entity NmsPatientRoom {
    begin ZonedDateTime,
    end ZonedDateTime
}
然后

relationship ManyToOne {
 NmsPatientRoom{patient} to NmsPatient,
 NmsPatientRoom{room} to NmsRoom
}

您可以拥有这些实体

entity NmsPatient {
photo ImageBlob
}

entity NmsRoom {
code String required,
name String required
}

entity NmsPatientRoom {
    begin ZonedDateTime,
    end ZonedDateTime
}
然后

relationship ManyToOne {
 NmsPatientRoom{patient} to NmsPatient,
 NmsPatientRoom{room} to NmsRoom
}

请考虑解释你的答案,以及为什么它会起作用。抱歉,但它不起作用。我仍然得到两个相同的@ManyToOne个人资料;这会导致错误。无论如何,请考虑解释你的答案,以及为什么它的工作。对不起,但它不起作用。我仍然得到两个相同的@ManyToOne个人资料;这会导致错误。无论如何,谢谢你能用这个例子来给出解决方案吗,因为Profile{follows(user)}到follows{Profile(id)}和Profile{follows(followerd)}到follows{Profile(id)}或者follows{user}到Profile和follows{followerd}到Profile都不起作用。感谢您仍然使用相同的关系名称。这些需要是独一无二的。如果不声明关系名称,则默认为实体名称。我使用JDLCan添加了一个示例,您可以使用该示例给出解决方案,因为Profile{follows(user)}到follows{Profile(id)}和Profile{follows(followerd)}到follows{Profile(id)}或follows{user}到Profile和followerd{followerd}到Profile不起作用。感谢您仍然使用相同的关系名称。这些需要是独一无二的。如果不声明关系名称,则默认为实体名称。我添加了一个使用JDL的示例