veluxer62 / veluxer62.github.io

veluxer's blog
http://veluxer62.github.io
MIT License
1 stars 0 forks source link

11월 개발이슈 #687

Closed veluxer62 closed 5 months ago

veluxer62 commented 7 months ago

Motivation

Suggestion

1

veluxer62 commented 7 months ago

YearMonth라는 자료형이 있네

JPA로 사용하려면 컨버터를 만들어야 하긴 하지만 나쁘지 않은듯

https://vladmihalcea.com/java-yearmonth-jpa-hibernate/

veluxer62 commented 7 months ago

YearMonth 의 월 차이를 계산하려면 아래와 같이 하면된다.

val gap = billingMonth.until(appliedDate, ChronoUnit.MONTHS).absoluteValue
veluxer62 commented 7 months ago

아래와 같이 repository.save에서 발생하는 에러를 try catch로 처리하려고 했을때 Flush에러를 catch에서 잡아주지 못하는 이슈가 있다.

JPA의 transactional 메커니즘 때문인것처럼 보이는데 자세히 뜯어봐야겠다.

class Service {
    @Transactional
    fun createDraft(billingMonth: YearMonth): List<MatchingFeeBill> {
        // 생략
        return try {
            matchingFeeBillRepository.saveAll(bills)
        } catch (e: Exception) {
           // 여기로 예외가 잡히지 않음
        }
    }
}

class Facade {
    fun createDraft(billingMonth: YearMonth): List<MatchingFeeBill> {
         return try {
            service.createDraft(billingMonth: YearMonth)
        } catch(e: Exception) {
             // 여기선 잡힘
        }
    }
}