假设你有一个拥有个人资料的Jhipster应用程序,需要注册哪些个人资料跟随其他个人资料,其中包含2个属性:一个用于跟随的用户(用户个人资料),另一个用于跟随用户(关注轮廓)。类似的东西:
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有2个相同的属性,即使名称不同,也跟随(用户)&如下(接着):
@ManyToOne
private Profile profile;
......而不是......
@ManyToOne
private Profile user;
@ManyToOne
private Profile followed;
感谢。
答案 0 :(得分:1)
您对两种关系使用相同的关系名称,但每个关系名称必须不同,否则字段会发生冲突。
relationship (OneToMany | ManyToOne | OneToOne | ManyToMany) {
<from entity>[{<relationship name>[(<display field>)]}] to <to entity>[{<relationship name>[(<display field>)]}]
}
JDL Relationship Declaration Docs
对于JDL示例,我将显示字段从user
/ followed
更改为id
,因为实体上不存在这些字段。重要的变化是关系名称是唯一的。
relationship OneToMany {
Profile{followed(id)} to Follows{followed(id)}
Profile{following(id)} to Follows{following(id)}
}
答案 1 :(得分:0)
entity Profile {
creationDate Instant required
}
entity Follows {
creationDate Instant
}
relationship ManyToOne{
Follows{user} to Profile
Follows{followed} to Profile
}
答案 2 :(得分:0)
您可以拥有这些实体
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
}