ORM 을 사용할 경우 Entity 를 save method를 사용해서
Insert 혹은 Update 를 할수 있다.
이때 Entity 의 모든 항목을 채워주지 않으면 해당 컬럼은 default 값이 잡혀 있지 않는 한 Null로 체크가 된다.
Default의 대해서는 db에서도 가능하지만 JPA에서 설정은 아래 참고포스팅을 참고바란다.
설정되지 않는 값들은 제외하고 설정하는 값들만 insert 와 update 를 되게 하려면
@DynamicInsert, @DynamicUpdate
를 사용하면 된다.
비슷한 내용의 stackoverflow 글이 있는데 도움이 될것이다.
https://stackoverflow.com/questions/21721818/why-does-not-hibernate-set-dynamicinsert-by-default
Why does not Hibernate set @DynamicInsert by default
Could anyone explain to me why Hibernate does not set the @DynamicInsert annotation by default and allow entities to generate an INSERT based on the currently set properties? What's the reason for ...
stackoverflow.com
참고 포스팅
https://thenicesj.tistory.com/793
@ColumnDefalut Annotation
이전 포스팅에서 lombok 에서 제공하는 Builder.Default 에 대해서 다룬적이 있다. 자세한 내용은 아래 참고 포스팅을 참고 바란다. 이번 포스팅에서는 @ColumnDefalut annotation이다. Builder.Default 와 비슷하
thenicesj.tistory.com
https://thenicesj.tistory.com/790
@Builder.Default [lombok]
자바에서 Dto 생성시 Builder를 자주 사용한다. 자세한 내용은 아래 참고 포스팅을 참고 바란다. 이번엔 이 builder를 사용하게 될때 값을 default로 셋팅할수 있는 annotation을 가져왔다. 만약 코드에서 T
thenicesj.tistory.com
'IT > Java' 카테고리의 다른 글
RequestEntity 란 (20) | 2024.01.13 |
---|---|
LocalDateTime 요일 구하기 (28) | 2024.01.11 |
UUID 생성(GUID) in Java (25) | 2024.01.06 |
[Error] After saving the identifier must not be null! (17) | 2024.01.04 |
숫자 자리수 0으로 채우기 (37) | 2023.12.28 |
댓글