Comments (3)
일단 오해를 하나 푸셔야하는데요 :)
JPA의 더티체킹은 save를 대체하지 않습니다
update를 대체한다고 보시면 됩니다.
영속성 컨텍스트에 포함된 엔티티들의 변경을 감지하는 것입니다.
처음 만들어진 엔티티들은 아직 영속성 컨텍스트 대상에 포함되지 않습니다.
- 트랜잭션 범위 내에서 save하거나
- 트랜잭션 범위 내에서 저장된 엔티티를 조회해온 경우
에만 해당됩니다.
-
두 코드 모두 테이블의 최종 상태는 동일합니다.
다만, 객체의 관점에서 난 내 상태를 변경했어에서 변경했지만 디비에도 반영은 또 따로 해줘야한단다 가 2번의 코드입니다.
1번은 객체가 자기 할일만 하는 코드로 끝난 상태이고요.
그래서 객체지향적인 관점에서 2번은 사실 좋은 형태로 보긴 힘듭니다. -
2번은 트랜잭션이 없을 경우 save하다가 잘못될 경우 롤백이 안되서 그렇습니다
save할때 연관관계에 의해 다른 엔티티들도 save/update 되야 한다거나
여러 엔티티를 한번에 저장해야한다거나
단일 엔티티를 저장하지만 저장후 update가 한번더 이루어져야한다거나
등등 다양한 케이스에서 전체 반영되거나 전체 취소되는 상황이 필요합니다.
결국 최종적으로 부분반영을 막기 위해 사용합니다.
- 일단은 트랜잭션 어노테이션이 없으면
@OneToMany
,@ManyToMany
와 같은 레이지 로딩이 필요한 엔티티들이 정상조회되지 않습니다.
JPA를 사용하다보면 부모-자식 관계 (@OneToMany)를 많이 사용하는데
이 옵션이 트랜잭션이 없으면 정상작동 하지 않습니다.
LazyInitializationException 가 바로 그런 경우입니다.
그래서 OneToMany나 ManyToMany와 같이 레이지 로딩을 지원하면서 롤백 기능이 없어 성능 향상이 어느정도 되어있는 readOnly 옵션을 사용한 것입니다.
from freelec-springboot2-webservice.
아! 명확히 이해갔습니다!! 친절하게 답변해주셔서 너무 감사합니다 ^^!
from freelec-springboot2-webservice.
@evan-hwang 넵 감사합니다 :) 이후에도 편하게 질문 남겨주세요!
from freelec-springboot2-webservice.
Related Issues (20)
- 제발 한 번만 도와주세요 ㅠㅠ.. vim nohup.out 에서 못넘어가는 내용입니다. HOT 2
- [오타 제보] p.260
- [오류] p.192 구글 로그인 오류 HOT 1
- [오류] p.145
- [오류] p.190 실행시 UnsatisfiedDependencyException 오류 HOT 1
- [오류] p.316
- [오류] p.214~215
- [오류] p.239
- [오류] p.260 날짜설정..
- [오류] p.118
- [306] p. nohup HOT 1
- [질문] [오류] p.188 직렬화가 가능한 sessionUser 클래스를 사용하는 이유를 잘 모르겠습니다.
- [오류] p.291 conflicting requests
- [오류] p.300 빌드하고 /libs 폴더와 .jars 파일들이 생성되지 않습니다.
- [오류] p.297 Execution failed for task ':test'.
- [오류] p.115 등록된다 assertion test failed
- [오류] p.252 AWS EC2 인스턴스 생성 실패 HOT 1
- [오류] p.214 application.properties를 추가후에도 똑같은 오류가 뜹니다.
- [오류] p.115 HOT 4
- [오류] 303p
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from freelec-springboot2-webservice.