GithubHelp home page GithubHelp logo

jpa's Introduction

Spring && JPA

Spring 강의

https://www.youtube.com/watch?v=HXXn3apd_04&list=PLlTylS8uB2fBOi6uzvMpojFrNe7sRmlzU&index=45

JPA

이번 글에서는 JPA(Java Persistence API)가 무엇인지 알아보려고한다. JPA는 자바 진영에서 (Object-Relational Mapping) 기술 표준으로 사용되는 인터페이스의 모음이다. 그 말은 즉, 실제적으로 구현된것이 아니라 구현된 클래스와 매핑을 해주기 위해 사용되는 프레임워크이다. JPA를 구현한 대표적인 오픈소스로는 Hibernate가 있다.

ORM(Object-Relational Mapping) 우리가 일반 적으로 알고 있는 애플리케이션 Class와 RDB(Relational DataBase)의 테이블을 매핑(연결)한다는 뜻이며, 기술적으로는 어플리케이션의 객체를 RDB 테이블에 자동으로 영속화 해주는 것이라고 보면된다.

JPA(Java Persistence API) Java 진영에서 ORM(Object-Relational Mapping) 기술 표준으로 사용하는 인터페이스 모음 자바 어플리케이션에서 관계형 데이터베이스를 사용하는 방식을 정의한 인터페이스 인터페이스 이기 때문에 Hibernate, OpenJPA 등이 JPA를 구현함

image image

intro

JPA는 단순하게 쿼리를 짜지않고, 코드도 적어서 개발 속도가 빨라짐.

  • 예시
    image

JPA 공부 목표

image

image

ORM

image

  • ORM(Object-relation mapping) : 객체 관계 매핑 프레임워크

  • JPA(Java persistence API : 자바 ORM 표준

  • hibernate : ORM Framework중 하나로 JPA 구현체 중 가장 많이 사용됨.

  • Srping Data JPA : Hibernate중에서 자주쓰이고 Spring에 최적화된 라이브러리 일부. image

  • JPA 구조
    image

image

지연 로딩 / 즉시 로딩

지연 로딩 : 객체가 실제 사용될 때 로딩
image
부모객체 member를 가져오고, getTeam()을 통해 자식객체(껍데기)를 가져왔는데, team.getName()을 호출하면 직접 db에 쿼리를 날려서 자식객체(Team)에 대한 정보를 가져옴.

즉시 로딩 : JOIN SQL로 한번에 연관된 객체까지 미리 가져옴.
image

: 대부분 지연 로딩으로 기본적으로 사용하고, 최적화가 필요할때 직접 필요한곳에 JPA옵션 세팅을 통해서 즉시로딩으로 변경함.

SQL JPQL JPA

SQL은 데이터베이스 테이블을 대상으로 조인해서 가져옴. JPQL은 엔티티 객체를 대상으로 쿼리로 가져옴. image
Member객체를 테이블로써 가져옴.

엔티티 vs 값타입

  • 기본값 타입 : int,double,Long, String 등 기본 타입들
  • 임베디드 타입 : 값을 묶어서 하나의 객체느낌으로 컬럼을 쓰고싶을때
  • 컬렉션 값 타입 :
기본값 타입은 절대 대입식으로 쓰면 안됨. 자바는 주소 참조방식이기 때문에
int a = 10;
int b = 0;
b = a; 를 선언하면 서로 객체가 참조되어 개발자의 의도는 b에 새로운값을 넣으려고했던건데 추후에 수정으로 a에도 변경이 생겨 사이드 이펙트가 일어날 수 있음.

임베디드 타입

주소 Address객체를 임베디드해서 사용하는데, Hone주소와 Work주소를 둘다 가지고 싶으면?

@AttributeOverrides, @AttributeOverride를 사용해서
컬러 명 속성을 재정의

단점 : 임베디드 타입은 여러 엔티티에서 공유해서 사용하면 문제가 생김. 그래서 여러 엔티티에서 공유하려고하면 차라리 엔티티로 만들어야함.

값 객체를 왜 VO를 생성하고, 파괴만 가능하고, 수정은 불가능하게 가이드 했는지?

member.getHomeAddress().setCity("수원시")로 update를 날려도
member2 엔티티(row)에도 update가 날아감...버그?

(JPA강의 - 값 타입과 불변 객체 - 6:00)

image
불변 객체를 통해서 부작용을 원천 차단 가능함. 불변객체는 Setter를 사용하지않고, 생성자에서 다 설정하고 수정 불가능해야함.

jpa's People

Contributors

wodonggun avatar

Watchers

James Cloos avatar  avatar

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.