用户对好友邀请列表有两个映射
@ManyToMany
@JoinTable(
name = "users_invitations",
joinColumns = {
@JoinColumn(name = "user_id", referencedColumnName = "id", nullable = false, updatable = false)
},
inverseJoinColumns = {
@JoinColumn(name = "user_invited_id", referencedColumnName = "id", nullable = false, updatable = false)
}
)
private List<UserEntity> sentInvitations;
@ManyToMany
@JoinTable(
name = "users_invitations",
joinColumns = {
@JoinColumn(name = "user_invited_id", referencedColumnName = "id", nullable = false, updatable = false)
},
inverseJoinColumns = {
@JoinColumn(name = "user_id", referencedColumnName = "id", nullable = false, updatable = false)
}
)
private List<UserEntity> receivedInvitations;
第一个列表是发送的邀请,第二个列表是接收的邀请。区别在于列
joinColumns
的命名,因此第一个字母是用户发送的邀请,第二个字母是发送给用户的邀请。不幸的是,由于已将其丢弃,因此无法编译[EL Warning]: 2017-12-14 23:52:04.361--UnitOfWork(1221584693)--Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.7.0.v20170811-d680af5): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: org.postgresql.util.PSQLException: ERROR: t0.user_invited_id column does not exist
Pozycja: 243
Error Code: 0
Call: SELECT t1.ID, t1.activation_token, t1.EMAIL, t1.email_change_token, t1.ENABLED, t1.modified_date, t1.new_email, t1.PASSWORD, t1.registration_date, t1.USERNAME, t1.UUID FROM users_invitations t0, users t1 WHERE ((t0.user_id = ?) AND (t1.ID = t0.user_invited_id))
bind => [1 parameter bound]
Query: ReadAllQuery(name="sentInvitations" referenceClass=UserEntity sql="SELECT t1.ID, t1.activation_token, t1.EMAIL, t1.email_change_token, t1.ENABLED, t1.modified_date, t1.new_email, t1.PASSWORD, t1.registration_date, t1.USERNAME, t1.UUID FROM users_invitations t0, users t1 WHERE ((t0.user_id = ?) AND (t1.ID = t0.user_invited_id))")
ERROR: t0.user_invited_id column does not exist
异常指出该列不存在。如何解决?
最佳答案
@ManyToMany中的名称值(此处为“ users_invitations”)相同。
@ManyToMany
@JoinTable(
name = "users_invitations",
名称值应该不同。