GithubHelp home page GithubHelp logo

Comments (3)

jojoldu avatar jojoldu commented on June 19, 2024 2

일단 오해를 하나 푸셔야하는데요 :)
JPA의 더티체킹은 save를 대체하지 않습니다
update를 대체한다고 보시면 됩니다.

영속성 컨텍스트에 포함된 엔티티들의 변경을 감지하는 것입니다.
처음 만들어진 엔티티들은 아직 영속성 컨텍스트 대상에 포함되지 않습니다.

  1. 트랜잭션 범위 내에서 save하거나
  2. 트랜잭션 범위 내에서 저장된 엔티티를 조회해온 경우

에만 해당됩니다.

  1. 두 코드 모두 테이블의 최종 상태는 동일합니다.
    다만, 객체의 관점에서 난 내 상태를 변경했어에서 변경했지만 디비에도 반영은 또 따로 해줘야한단다 가 2번의 코드입니다.
    1번은 객체가 자기 할일만 하는 코드로 끝난 상태이고요.
    그래서 객체지향적인 관점에서 2번은 사실 좋은 형태로 보긴 힘듭니다.

  2. 2번은 트랜잭션이 없을 경우 save하다가 잘못될 경우 롤백이 안되서 그렇습니다
    save할때 연관관계에 의해 다른 엔티티들도 save/update 되야 한다거나
    여러 엔티티를 한번에 저장해야한다거나
    단일 엔티티를 저장하지만 저장후 update가 한번더 이루어져야한다거나
    등등 다양한 케이스에서 전체 반영되거나 전체 취소되는 상황이 필요합니다.

결국 최종적으로 부분반영을 막기 위해 사용합니다.

  1. 일단은 트랜잭션 어노테이션이 없으면 @OneToMany, @ManyToMany와 같은 레이지 로딩이 필요한 엔티티들이 정상조회되지 않습니다.
    JPA를 사용하다보면 부모-자식 관계 (@OneToMany)를 많이 사용하는데
    이 옵션이 트랜잭션이 없으면 정상작동 하지 않습니다.
    LazyInitializationException 가 바로 그런 경우입니다.
    그래서 OneToMany나 ManyToMany와 같이 레이지 로딩을 지원하면서 롤백 기능이 없어 성능 향상이 어느정도 되어있는 readOnly 옵션을 사용한 것입니다.

from freelec-springboot2-webservice.

evan-hwang avatar evan-hwang commented on June 19, 2024

아! 명확히 이해갔습니다!! 친절하게 답변해주셔서 너무 감사합니다 ^^!

from freelec-springboot2-webservice.

jojoldu avatar jojoldu commented on June 19, 2024

@evan-hwang 넵 감사합니다 :) 이후에도 편하게 질문 남겨주세요!

from freelec-springboot2-webservice.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.