Giter Site home page Giter Site logo

Comments (1)

djkeh avatar djkeh commented on August 16, 2024 1

버그는 equals(), hashcode() 안에서 각 클래스 필드들을 비교하기 위해 접근할 떄, 직접 접근(direct field access)을 했기 때문이다.
jpa 엔티티는 그대로 인스턴스로 만들어 사용하는게 아니라, jpa 구현체 - spring data jpa 에서는 하이버네이트 - 에 의해 프록시 인스턴스로 만들어진다.
때문에 직접 접근을 하면 프록시가 되기 전, 후 인스턴스의 차이로 equals, hashcode 가 제대로 각 필드를 참조하지 못할 수 있다.
하지만 getter 와 같이 메소드를 이용해 필드에 접근하면 프록시 인스턴스가 된 이후에도 명확하게 각 필드에 접근할 수 있기 때문에
entity 안의 quals, hashcode를 구현할 때는 getter를 사용해야 한다.

이를 정리한 기술 블로그가 여럿 있는데, 그 중 유명한 jpa buddy 플러그인을 만드는 회사의 블로그 글을 첨부하니 공부에 참고할 것.
내용이 많은데 getter method로 검색하면 원하는 문서 부분을 좀 더 빨리 찾을 수 있다.

from fastcampus-project-board.

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.