인프런 영문 브랜드 로고
인프런 영문 브랜드 로고

인프런 커뮤니티 질문&답변

HappyJay님의 프로필 이미지
HappyJay

작성한 질문수

자바 ORM 표준 JPA 프로그래밍 - 기본편

@Id 관련해서 질문이 하나 더 있습니다...

작성

·

244

0

@Entity
@Getter @ToString
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
@Builder
@Table(name = "CURRENCYTYPE")
public class CurrencyType {
    @Id
    @Column(length = 3, unique = true)
    private String currency;
    private String description;

    @Column(length = 1, nullable = false)
    @ColumnDefault("0")
    private Integer decimalPoint;
}

위에 처럼 선언한 이후에 해당 entity 를 save 하면

selete 쿼리가 수행됩니다. 혹시 이유를 알 수 있을까요?

그리고 currency 컬럼에 동일값을 넣어라도 unique 제약조건에 의한 exception 이 발생하지 않고

insert 쿼리만 수행되지 않은 채 정상종료되어 버립니다.

이건 왜 그런 건가요?

    public void findById() {
        CurrencyType currencyType = CurrencyType.builder()
                .currency("USD")
                .description("Canadian dollar")
                .decimalPoint(2)
                .build();

        System.out.println("out - 0======================");
        currencyTypeRepository.save(currencyType);
        System.out.println("out - 1======================");
}

out - 0======================

2021-04-24 23:13:51.191 DEBUG 1454156 --- [    Test worker] org.hibernate.SQL                        : 

    select

        currencyty0_.currency as currency1_0_0_,

        currencyty0_.decimal_point as decimal_2_0_0_,

        currencyty0_.description as descript3_0_0_ 

    from

        currencytype currencyty0_ 

    where

        currencyty0_.currency=?

out - 1======================

답변 1

0

김영한님의 프로필 이미지
김영한
지식공유자

안녕하세요. HappyJay님

스프링 데이터 JPA를 사용하시는 군요.

실전! 스프링 데이터 JPA 강의

스프링 데이터 JPA 분석 섹션에 있는 스프링 데이터 JPA 분석, 스프링 데이터 JPA 분석 두 강의 영상을 참고해주세요.

추가로 다음 링크도 읽어보시면 도움이 되실거에요.

https://www.inflearn.com/questions/197446

감사합니다.

HappyJay님의 프로필 이미지
HappyJay

작성한 질문수

질문하기