본문 바로가기
Error

[Java / Spring / JPA / Error] - Inferred type 'S' for type parameter 'S' is not within its bound; should extend 'java.lang.Long'

by nam_ji 2024. 7. 29.

Inferred type 'S' for type parameter 'S' is not within its bound; should extend 'java.lang.Long'

에러

Inferred type 'S' for type parameter 'S' is not within its bound; should extend 'java.lang.Long'

에러 원인

  • JPA의 JpaRepository 매개변수, 인터페이스 명이 일치한 지 확인하면 된다고 합니다.

에러 해결 방안

  • 저는 Service Layer에서 에러가 발생했습니다.
    •   public GroupResponse createGroup(GroupRequest groupRequest) {
          Group group = groupRepository.findByStationGroupSerial(groupRequest.getStationGroupSerial());
      
          if (group != null) {
            throw new IllegalArgumentException("일치하는 그룹이 존재합니다.");
          }
      
          Group saveGroup = new Group(groupRequest.getStationGroupSerial());
      
          groupRepository.save(saveGroup); // 에러 발생
      
          return new GroupResponse(
              saveGroup.getStationGroupId(),
              saveGroup.getStationGroupSerial(),
              saveGroup.getCreateAt());
  • 원인을 찾기 위해 Repository Layer를 보니
    • @Repository
      public interface GroupRepository extends JpaRepository<Long, Group> {
      
        Group findByStationGroupSerial(String stationGroupSerial);
        
      }
  • Group과 Long이 바뀌어 있었습니다.
    • @Repository
      public interface GroupRepository extends JpaRepository<Group, Long> {
      
        Group findByStationGroupSerial(String stationGroupSerial);
      
      }
  • 이렇게 수정 후 해결했습니다.