Spring boot

JPA 복합 Primary Key 설정하기 (@IdClass)

lipnus 2019. 7. 24. 10:08
반응형


2개의 컬럼(ciNo, time)을 동시에 Primary Key로 정하고 싶을 때


@IdClass를 사용



HwCurrentVO 클래스

@Entity
@Table(name = "hw_current")
@Data
@Accessors(chain = true)
@IdClass(HwCurrentVOKey.class)
public class HwCurrentVO {

@Id
String ciNo;
String hostName;
Double cpu;
Double cpuAvg;
Double mem;
Double memSum;
Double cur;
Double curSum;
@Id
LocalDateTime time;
}



HwCurrentVOKey 클래스

public class HwCurrentVOKey implements Serializable {
String ciNo;
LocalDateTime time;
}


반응형