我有一个实体,它具有两个具有复合键的相同实体的复合键。保持一切不变,我将得到一个表,其中主键将是一组四列(first_profile_user_id, first_profile_chat_id, second_profile_user_id, second_profile_chat_id)
但是,如果chatId第一个和第二个配置文件始终具有相同的配置文件,我可以以某种方式将这些列合并first_profile_chat_id为second_profile_chat_id一个吗?如何做到这一点?
@Entity
class Relation {
@EmbeddedId
private RelationFK fk;
@Embeddable
public static class RelationFK implements Serializable {
@ManyToOne(fetch = FetchType.LAZY)
private Profile firstProfile;
@ManyToOne(fetch = FetchType.LAZY)
private Profile secondProdile;
}
}
@Entity
class Profile {
@EmbeddedId
private ProfilePK pk;
@Embeddable
public static class ProfilePK implements Serializable {
private Long chatId;
private Long userId;
}
}
首先,先生对微妙的变态了解很多:)
我将创建一个由三个字段和两个 Ridon 字段组成的复合键来接收实体。