3 回答
TA贡献1794条经验 获得超8个赞
尝试指定联接列:
@OneToOne
@JoinColumn(name = "username", referencedColumnName = "username")
private profile profile;
你真的不需要这里。@MapsId
TA贡献1862条经验 获得超7个赞
不要忘记禁用JoinColumn的可插入和可更新
@OneToOne
@JoinColumn(name = "username", referencedColumnName = "username", updatable = false, insertable = false)
private profile profile;
TA贡献1995条经验 获得超2个赞
我建议创建第三个表,并为您的表建立关系
@Entity
@Table(name = "M_USER")
public class User {
@OneToOne(fetch = FetchType.LAZY)
@JoinTable(
name = "user_profile",
joinColumns = @JoinColumn(name="user_id"),
inverseJoinColumns = @JoinColumn(name="profile_username")
)
private Profile profile;
UPDATE user_profile
SET user_id = (
SELECT id
FROM M_USER
);
UPDATE user_profile
SET profile_username = (
SELECT username
FROM M_USER
);
添加回答
举报