728x90
JPA에서 복수키 만들기
@IdClass(OhlcvHour.OhlcvHourKey.class)
public class OhlcvHour {
@Id
private String currencyPair;
@Id
private LocalDateTime timeToHours;
@EqualsAndHashCode
@Embeddable
static class OhlcvHourKey implements Serializable {
@Column(columnDefinition = "varchar(10)")
private String currencyPair;
@Column(name = "TIME_TO_HOURS", nullable = false)
private LocalDateTime timeToHours;
}
}
복수키를 만들려면 위와 같이 @Id Annotation을 두개를 붙여준다.
그리고 @IdClass annotation으로 local class를 만들어주어서 붙여주면 복수키를 만들 수 있다.
복수키를 만들때 길이 문제
@Column(columnDefinition = "varchar(10)")
private String currencyPair;
[42000][1071] Specified key was too long; max key length is 1000 bytes
위 에러가 날 때가 있다 key가 1000 bytes를 넘으면 안된다는 에러이다.
그럴때 위와 같이 해결 할 수 있다.
728x90
'Spring > Spring Data JPA' 카테고리의 다른 글
jpa app 운영 배포 전략 (0) | 2019.03.13 |
---|---|
jpa에서 복수키 만들기(key 2개), 복수키를 사용할 경우 길이 문제 (0) | 2019.01.08 |
jpa 강좌 주제 (0) | 2019.01.08 |
Spring Data Jpa - mysql LocalDateTime은 timestamp로, BigDecimal은 decimal mapping하기 (0) | 2019.01.03 |
Spring Data Jpa에서 LocalDateTime이용해서 자동으로 createdAt만들기 (0) | 2018.06.08 |
@SpringBootTest와 @DataJpaTest 차이점 (0) | 2017.07.05 |