private void validateAlreadyIssued(Long memberId, Long couponId) {
        try {
            // return multiple result when transaction confilcted
            memberCouponRepository.findByMemberIdAndCouponId(memberId, couponId);
        } catch (IncorrectResultSizeDataAccessException e) {
            log.info("expected size = {}, actualSize = {}", e.getExpectedSize(), e.getActualSize());
            log.info("mesage = {}", e.getMessage());

            throw new IllegalStateException("transaction conflict");
        }
    }
2024-09-28T14:18:12.153+09:00  INFO 6651 --- [ool-2-thread-28] coupon.application.MemberCouponService   : expected size = 1, actualSize = -1
2024-09-28T14:18:12.153+09:00  INFO 6651 --- [ool-2-thread-28] coupon.application.MemberCouponService   : mesage = Query did not return a unique result: 8 results were returned

when I checking the logs, actualSize is -1. It seems strange for me. because the message generated by hibernate (hibernate.NonUniqueResultException) contains the actual result size.

Since hibernate.NonUniqueResultException does not provide the result count, I changed HibernateJpaDialect that actualSize extracted from message generated by hibernate.

If there's anything I've overlooked, I'd appreciate your feedback. 🙇🏻‍♂️

Comment From: pivotal-cla

@le2sky Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

Comment From: pivotal-cla

@le2sky Thank you for signing the Contributor License Agreement!

Comment From: snicoll

Thanks for the PR.

when I checking the logs, actualSize is -1. It seems strange for me. because the message generated by hibernate (hibernate.NonUniqueResultException) contains the actual result size.

It's -1 as we couldn't know for sure what it was. You can see it's used by EmptyResultDataAccessException when we know what the actual size is.

Checking for the presence of any number in the exception message is too brittle for us to consider it. You may want to move this code in your own arrangement if you really care about the actual size.