꿀똥벌레
꿀똥벌레 개발 블로그
꿀똥벌레
전체 방문자
오늘
어제
  • 분류 전체보기 (90)
    • JAVA (17)
    • SPRING (14)
    • Elasticsearch (4)
    • GRADLE (2)
    • HTML, CSS (0)
    • JAVASCRIPT (0)
    • GIT (1)
    • Vue.js (1)
    • server (1)
    • Python (0)
    • IT리뷰 (0)
    • 인프라 (6)
    • IOS (21)
    • 디자인패턴 (20)
    • Kafka (1)

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

인기 글

태그

  • maxConnTotal
  • 스프링 인테그레이션
  • maxConnPerRoute
  • spring integration
  • 인덱스 템플릿
  • 스프링 인티그레이션
  • KEEPALIVE
  • elasticsearch
  • 엘라스틱서치
  • persistent connection
  • persistence connection
  • connectionRequestTimeout
  • ES
  • spring
  • springintegration
  • SWIFT
  • Index
  • mappings
  • java
  • Index Template

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
꿀똥벌레

꿀똥벌레 개발 블로그

JAVA

JPA Entity와 DB값 간 매핑

2021. 4. 28. 13:26

Entity 값과 DB값 간 매핑

  • 엔티티의 boolean 값을 DB에 저장시에는 Y, N 값으로 저장하고 싶을때 등 사용.
@Entity
public class aaa {
    ...
    @Convert(converter=BooleanToYnConverter.class)
    private boolean isExist;
}

@Converter
//@Converter(autoApply = true) autoApply를 true로 설정하면
//모든 AttributeConverter로 설정한 타입 값을 가진 엔티티 필드 타입에 자동 적용된다.
public class BooleanToYnConverter implements AttributeConverter<Boolean, String> {
    @Override
    public String convertToDatabaseColumn(boolean attribute) {
        return attribute to string code;
    }

    @Override
    public Boolean convertToEntityAttribute(Boolean dbData) {
        return String to boolean code;
    }
}

'JAVA' 카테고리의 다른 글

JPA 엔티티 그래프  (0) 2021.04.28
JPA 엔티티 생명주기에 리스너 등록  (0) 2021.04.28
JPA 지연로딩  (0) 2021.04.28
JPA @ManyToMany  (0) 2021.04.23
JPA @Inheritance  (0) 2021.04.23
    꿀똥벌레
    꿀똥벌레
    개발자 꿀똥벌레 입니다.

    티스토리툴바