Spring JPA 复合主键配置
1. 创建复合主键类,类上添加@Embeddable注解,注意要实现 Serializable 接口
import lombok.Data;
import javax.persistence.Column;
import javax.persistence.Embeddable;
import java.io.Serializable;
@Data
@Embeddable
public class PriKey implements Serializable {
private String icId;
private String orgId;
}
2. 实体类上使用复合主键类最为主键属性,属性上添加@EmbeddedId注解
import lombok.Data;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.Table;
@Data
@Entity
@Table(name = "tbl_ic_study_task")
public class IcStudy {
@EmbeddedId
private PriKey priKey;
private String type;
}