@EmbeddedId 키 클래스 생성

By | 2022년 11월 23일
Table of Contents

@EmbeddedId 키 클래스 생성

@EmbeddedId 키 클래스 조건

  • @EmbeddedId 어노테이션을 붙여줘야 한다.
  • Serializable 인터페이스를 구현해야 한다.
  • 기본 생성자가 있어야 한다.
  • 식별자 클래스는 public 이어야 한다.
@Embeddable
@NoArgsConstructor
@AllArgsConstructor
public class CommuteLogKey implements Serializable {
    private String yyyymmdd;
    private String userId;
    private Integer inoutType;

    @Override
    public int hashCode() {
        return Objects.hash(yyyymmdd, userId, inoutType);
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) return true;
        if (obj == null || getClass() != obj.getClass()) return false;
        CommuteLogKey k = (CommuteLogKey) obj;
        return Objects.equals(yyyymmdd, k.yyyymmdd) && Objects.equals(userId, k.userId) && Objects.equals(inoutType, k.inoutType);
    }
}

답글 남기기