HomeAboutMeBlogGuest
© 2025 Sejin Cha. All rights reserved.
Built with Next.js, deployed on Vercel
🛁
공부기록
/
🧑🏻‍💻
TIL
/
TIL - 23

TIL - 23

태그
Spring
JPA
날짜
May 9, 2022
속성

Part1 - JDBC

학습목표

  • JPA 소개
    • ApplicationLayer 에서 Database Layer에 접근하는 방법에 대해 학습한다.
    • Jdbc Template, 쿼리매퍼 (Mybatis) 소개
    • ORM(JPA)
    • JPA란 무엇인가?
    • JPA의 필요성을 알아보자.
  • JPA 프로젝트 시작하기
    • JPA 실습을 위한 환경 세팅

Spring Frameworks을 활용한 데이터 레이어(RDB) 접근 방법

JDBC

  • 자바 애플리케이션은 JDBC API를 이용하여 데이터계층과 통신한다.
    • notion image

Part2 - Mybatis

spring: datasource: driver-class-name: org.h2.Driver url: jdbc:h2:~/test; username: sa password: # https://mybatis.org/spring-boot-starter/mybatis-spring-boot-autoconfigure/ mybatis: type-aliases-package: com.example.practice.repository.domain configuration: map-underscore-to-camel-case: true default-fetch-size: 100 default-statement-timeout: 30 mapper-locations: classpath:mapper/*.xml
  • type-aliases-package
    • jdbcTemplate 사용하면 ResultSet에 쿼리 결과가 담겨져 오게되어 각각 로우넘버마다 꺼내서 사용해야 했었다.
    • 이것은 많은 번거로움이 있었지만 마이바티스는 연결해둔 도메인 즉 자바 객체에 resultet의 결과를 자동으로 매핑해준다.
    • 쿼리결과를 어떤 객체에 매핑할지 어떤 패키지에 명시해줄건지를 설정해주는 것이다.
  • configuration 기본 설정이다
    • map-underscore-to-camel-case
      • 보통 필드명은 디비에 카멜케이스가 아니라 스네이크케이스다 이걸 카멜로 변경해준
    • default-fetch-size
      • select 시 최대 100개 가져오겟다.
    • default-statement-timeout
      • jdbc statement객체를 통해 쿼리를 날렸다 이 통신하는 객체 타임아웃을 몇초로 가져갈건지
  • mapper-location
    • xml을 어디에 관리할건지 설정해준다.
jdbcTemplate나 쿼리매퍼는 rdb 와 자바 객체가 가지는 기본적인 패러다임에 불일치가 생긴다. 이런 한계를 jpa를 통해 극복을 할 수 있다.