티스토리 뷰
h2에서
을 이용하는 소스가 있었는데,
DB를 mysql로 바꾸고 @Column(nullable=false) 했더니 default 컬럼 값에 문제가 있다고 실행 실패
JPA로 mysql에서 Datetime 컬럼에 생성일/수정일이 자동으로 들어가게 하는 두 가지 방법
엔티티 내에서 다음 코드 사용
1.
@CreationTimestamp
private Instant createdAt;
2.
private LocalDateTime createdAt;
@PrePersist
public void createdAt() {
this.createdAt = LocalDateTime.now();
}
날짜, 시간이 잘 입력됨
참고
https://stackoverflow.com/questions/40370709/createddate-annotation-does-not-work-with-mysql
@CreatedDate annotation does not work with mysql
I am new to spring and I am confused how @CreatedDate annotation works in an entity. I did a google search and there were many solutions, but none of them worked for me except one. I am confused ...
stackoverflow.com
https://krksap.tistory.com/1268
Spring Data Jpa에서 LocalDateTime이용해서 자동으로 createdAt만들기
Spring Data Jpa에서 LocalDateTime이용해서 자동으로 createdAt만들기 개요 쇼핑몰에서 사용자가 물건을 구매 한다고 했을 때 언제 구매를 했는지 그리고 결제를 했다면 언제 결제를 했는지 등 날짜, 시간
krksap.tistory.com
'이슈,버그' 카테고리의 다른 글
websecurityconfigureradapter is deprecated 이슈 및 해당 버전의 authenticationManager 설정 (0) | 2023.01.18 |
---|---|
자바 에러 java.lang.NoClassDefFoundError: javax/xml/bind/DatatypeConverter (0) | 2023.01.17 |
Mysql Public key retrieval is not allowed 에러 (0) | 2023.01.09 |
Unable to find GatewayFilterFactory with name 오류 (0) | 2023.01.09 |
VS코드 스프링부트 실행 안되는 오류 (0) | 2023.01.08 |