简体   繁体   English

具有两个多对一关系的实体关系

[英]Entity relation with two many to one relations

I need to implement user invitations and i have a little problem with mapping entities. 我需要实现用户邀请,并且映射实体有点问题。 I have User entity which have set of invitations and a invitation have User field and inviting User field. 我有具有邀请集的用户实体,并且邀请具有用户字段和邀请用户字段。 In this way I have two User fields that are the same. 这样,我有两个相同的用户字段。

User side: 用户端:

@OneToMany(mappedBy="user")
public Set<Invitation> invitations;

Invitation: 邀请:

@ManyToOne
@JoinColumn(name="idInvitingUser", insertable=false, updatable=false)
public User invitingUser;

@ManyToOne
@JoinColumn(name="idUser")
public User user;

How can I map this proper ? 我该如何映射这个适当的?

I guess you will need two sets of invitations on the user side: invitations sent and invitations received. 我想您在用户端需要两组邀请:已发送的邀请和已接收的邀请。

UPDATE: 更新:

@OneToMany(mappedBy="user")
public Set<Invitation> invitations;

@OneToMany(mappedBy="invitingUser")
public Set<Invitation> invitationsSent;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM