WookjeBlog
    • 블로그
    • 소개
    • 태그
    • 수업/강의
    • 라이브러리
    Main
    • Share to Facebook

    JPA

    All Posts in jpa

    • Kotlin에서 JPA 기본 repository interface 사용시 불편한 점

      JPA의 respository interface를 코틀린에서 사용하면 조금 불편한 상황이 발생한다. interface SometingRepository : CrudRepository<Something, Long> { // (1) fun findById(id: Long): Something? // (2) fun findByIdAndActiveIsTrue(id: Long): Something? } val entity = somethingRespoitory.findById(id); 여기서 entity의 type은 Optional<T>이다. 왜냐면 interface가 Optional<T> findById(ID var1); 이렇게 생겼기 때문이다. 이 interface는 Optional<Something!>를 뱉는다. 그러면 어떤 문제가 벌어질까? entity.get()으로 그 안에 들어있는 데이터를 가져올 수 있다. /** * If a value is present, returns the value, otherwise throws * {@code NoSuchElementException}....

      jpa kotlin

      wookje.kwon's profile image

      wookje.kwon

      2020-07-16 16:38

    • github
    • facebook
    • rss

    Copyright © Wookje Kwon. All rights reserved.