@Entity
@Table(name = "cm_user_organization_role")
@IdClass(CmUserOrganizationRoleVo.class)
@SuppressWarnings("serial")
public class CmUserOrganizationRoleVo implements Serializable{
@Id
@Column(name = "user_code")
private String userCode;
@Id
@Column(name = "organization_code")
private String organizationCode;
@Id
@Column(name = "group_code")
private String groupCode;
将联合主键的字段单独放在一个类中,该类需要实现java.io.Serializable接口并要重写equals和hashcode.最后在主类中(该类包含联合主键类中的字段)将联合主键字段都注解为@Id,并在该类上方将上这样的注解:@IdClass(联合主键类.class)
1、数据库的每张表只能有一个主键,不可能有多个主键。
2、所谓的一张表多个主键,我们称之为联合主键。
注:联合主键:就是用多个字段一起作为一张表的主键。
3、主键的主键的作用是保证数据的唯一性和完整性,同时通过主键检索表能够增加检索速度。