Flamme Dev
  • IntroduceMyself
  • GOAL
    • 2021년 목표
    • 회고록
      • 2020년
  • COMMON
    • 자료구조
      • 시간복잡도
      • 스택/큐
    • 코드리뷰/스터디/세미나
      • Semina
        • Version control -1 (SVN/GIT)
        • Version control - 2 (GIT)
        • PostMan
        • JMeter
      • 스터디
        • 2021년
          • EffectiveKotlin
          • 이펙티브자바
        • 2020년
          • JPA Study
            • Chap1
            • Chap3
            • Chap4
            • Chap5
            • Chap6
            • Chap7
            • Chap8
            • Chap9
            • Chap10 -1
            • Chap10-2
            • Chap10-3
            • Chap12
            • Chap 13. 웹 애플리케이션과 영속성 관리
            • Chap14
      • 코드리뷰
        • Page 1
        • 개발 생각
        • APNs 라이브러리 교체
        • 파일 삭제 분투기
        • 신입 코드리뷰
          • 2020-09-02
          • 2020-09-03
          • 2020-09-10
        • Repository
          • Repositroy(20201124)
          • Repositroy(20201123)
          • Repositroy(20201120)
          • Repositroy(20201119)
          • Repositroy(20201117)
    • 개발 서적 / 동영상 강의
      • 동영상 강의
        • 진행 중
        • 완주한 것
      • 개발 서적
        • 읽은 것
          • 손에 잡히는 10분 SQL
            • 인덱스
            • 정리 본
        • 진행 중
          • 폴리글랏 프로그래밍
          • DDD-START
            • Chapter5 리포지터리의 조회 기능
            • Chapter4 리포지터리와 모델 구현
            • Chapter3 애그리거트
            • Chapter2 아키텍쳐 개요
            • Chapter1 도메인 모델의 시작
  • INFO
    • 유스콘 준비
    • intellij
      • Command line is too long.
    • 프로그래밍의 종류
      • Async Await
      • Reactive Programming
      • Imperative Programming
      • Functional Programming
        • Naver D2 함수형 프로그래밍 강의
      • Object Oriented Programing
        • 객체지향에 대해서 알아보는 영상
      • ProcedureOriented Programming
      • RX(ReactiveX)
      • OOP VS FP
      • Declarative Programming
    • Language
      • Kotlin
        • 박재성님 강의
        • Kotlin Spring CGLIB Error
        • Kotlin의 사용
        • coroutine
        • Kotlin JVM
      • JavaScript
      • JAVA
        • DefaultNonnull
        • effective78
        • Exception
        • JsonUnWrappers
        • 명명짓기
        • @JsonFormat(with = JsonFormat.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY)
        • Enc Key
        • ServiceLoader
        • Annotation
        • JVM(Java Virtual Machine)
        • Java8
          • Functional 사용
          • Optional
          • Invalid Key size
        • Java13
          • Text Block
        • Basic
          • Generic
          • JVM
          • Interface, Implements
    • Framework
      • NodeJs
      • Xamarin
      • Vert.x
        • vert.x in action
        • eventbus
      • blockedthreadchecker
      • Why.. not root run..
      • Spring
        • Spring Test
        • Kotlin
        • ControllerAdvice 정리
        • JsonAnnotation
        • Spring Data R2DBC
        • SpringWebFlux
          • login
          • SpringWebFlux란?
        • JPA
          • QueryDSL 객체 주소값 확인할 것
          • SpringData-JPA에서 Save, SaveAll
          • @CompositeKey에 ManyToOne JoinColumn이 있을 경우
          • QueryDSL N+1 문제(@OneToOne)
          • QueryDSL설정
          • CreationTimestamp
          • Enum(@enumerated vs @convert)
        • SpringSecurity
          • aopAlliance
          • csrf 방어
          • antMatcher vs mvcMatcher
          • SpringSecurity를 왜 써야할까?
          • CoreSpringSecurity
            • AuthenticationProvider
            • AuthenticationManager
            • Authentication Flow
            • SecurityContextPersistenceFilter
            • SecurityContextHolder, SecurityContext
            • Authentication
            • 필터 초기화와 다중 보안 설정
            • DelegatingProxyChain, FilterChainProxy
            • 사이트 간 요청 위조 - CSRF, CsrfFilter
            • 예외 처리 및 요청 캐시 필터 : ExceptionTranslationFilter, RequestCacheAwareFilter
            • 인가 API - 권한 설정 및 표현식
            • SessionManagementFilter, ConcurrentSessionFilter
            • 동시 세션 제어 / 세션고정보호/ 세션 정책
            • AnonymousAuthenticationFilter
            • RememberMeAutheticationFilter
            • Logout,LogoutFilter
            • UsernamePasswordAuthenticationFilter
            • Form인증
            • 인증 API - 사용자 정의 보안 기능 구현
            • 인증 API - 스프링 시큐리티 의존성 추가
        • SpringMVC
          • Spring Bean Q&A
          • HttpServletRequest
          • @ControllerAdvice
          • Service와 ServiceImpl은 꼭 있어야할까?
          • SpringMVC-1
          • SpringMVC - validator와 Errors
          • SpringMVC - DispatcherServlet의 URL
          • Spring MVC - 기본설정(2) 및 HandlerInterceptor
          • SpringMVC-3
          • Spring MVC - ViewResolver
          • Spring MVC - XML/JSON
          • Spring MVC - Field Injection & Constructor Injection
        • SpringEtc
          • Transactional
          • @Atowired NullPointer
          • CircleReference
          • Mybatis
            • IBatis - sql에 Map
            • 1:1 Mapping시 Null
            • auto_Increment, selectKey
          • @Transactional
          • JacksonAnnotation
        • SpringAOP
        • SpringDI
    • Server
      • PM2
      • Tomcat
        • jks
        • Virtual Host(Port)
    • OS
      • Window
        • Active directory
      • IOS
      • Linux
        • samba/keroberos
        • Linux
          • unlimit / socket backLog
          • nohup
          • ; , & , &&, {}
          • 쉘
          • rc.local
          • ps aux | grep 프로세스이름
          • Vim
          • Su, Sudo
          • File Directory
        • IdConfig
        • 유용한 커맨드
        • 리눅스 대소문자
        • 소프트링크와 하드링크의 차이
        • ln -Tfs
        • //와 / 의 차이
        • Linux(202003)
          • rm
          • diff
          • cp
          • mv
          • tar 압축 시 어떻게 심볼릭 링크도 같이 압축할까?
          • tar 명령어
          • ln -s 심볼릭 링크
    • Network
      • API Architectural Styles
      • 포트 확인
      • HeartBeat Protocol
      • SSO(Single Sign On)
      • Cookie and Session
      • Tcp HandShake
      • WireShark
        • WireShark 옵션
        • WireShark 패킷분석
    • DataBase
      • DB락에 대해서 알아보기
      • Redis
      • MYSQL
        • Mysql TimeOut 설정
        • MysqlLog
        • SlowQuery Analyzing
        • PushNotification Stress Test
      • MSSQL
      • 데이터베이스 식별자 선택 전략
    • ETC
      • 이름 짓기
      • FFProbe
      • Talk
      • Untitled
Powered by GitBook
On this page

Was this helpful?

  1. INFO
  2. Framework
  3. Spring
  4. JPA

Enum(@enumerated vs @convert)

PreviousCreationTimestampNextSpringSecurity

Last updated 4 years ago

Was this helpful?

Persisting enums with JPA 2.0 is possible, but there is no nice way to do it. Using the @Enumerated annotation, you can use EnumType.ORDINAL or EnumType.STRING to map the enum value to its database representation. But both options have their drawbacks. The ordinal of an Enum depends on the ordering of its values and can create problems, if we need to add new ones. The String representation of an Enum is often quite verbose and renaming a value will break the database mapping. These drawbacks can be avoided by using an Attribute Converter.

ORDINAL로 설정 후 Gender enum 타입이 변경된다면 예기치 못한 문제가 발생할 수 있다.

ORDINAL은 서수로 표현되기 때문이다

enum test {
    male, female // 0,1 로 각각 저장됨. 
}

STRING 설정은 문자열 자체가 저장되기 때문에 DB 공간 낭비가 발생한다.

male, female 자체로 저장이 된다.

그래서 서수와 String을 직접적으로 들어가는 것을 피하기 위해 @Convert를 사용한다.

이걸 이용하면 될 듯하다.

JPA 2.1 Attribute Converter - The better way to persist enums - Thorben JanssenThorben Janssen
Legacy DB의 JPA Entity Mapping (Enum Converter 편) - 우아한형제들 기술 블로그우아한형제들 기술 블로그
Logo
https://tech.yangs.kr/16tech.yangs.kr