intellij +springboot/오류정리

Cannot project java.lang.Byte to java.lang.Boolean. Target type is not an interface and no matching Converter found

jeongyj 2022. 6. 22. 11:07

 

 

JPA를 사용하여 컬럼캆을 리턴할때 쿼리로 리턴했을때는 문제가 없는데 리턴 받을떄 매핑이 제대로 안되는 문제가 있었다 union을 사용해 테이블 2개를 리턴받아 하나의 테이블 처럼 사용하려 했는데

 

 

왜 이런 문제가 발생했는지는 모르겠다 컬럼 타입은 tinyint 리턴타입은 Boolean 0 으로 리턴받으면 false 1일떄 true 로 들어가야 하는데 union 위쪽은 잘 되는데 아래쪽이 문제가 있었다

 

    @Query(value = " select n.id, n.content as content, date_format(n.created_at,'%Y-%m-%d') as createdAt, n.alarm_content as alarm_content, n.is_read as isRead " +
 " from notification n " +
   " where n.fk_user_id =?1 " +
    " UNION select a.id, a.body as body, date_format(a.created_at,'%Y-%m-%d') as acreatedAt2, a.role as role, a.alarm_is_read as alarm_is_read " +
  " from  alarm a " +
            "where a.role in(?3) " +
            " limit 30 offset ?2 ", nativeQuery = true)
    List<NotificationVO> findNotifications(long userId, int offset, int change_role);

 

이것저것 해보다 그냥 case when 문으로 강제로 true false 로 타입을 맞춰주니 잘 변환 됐다

select n.id, n.content as content, date_format(n.created_at,'%Y-%m-%d') as createdAt, n.alarm_content as alarm_content,
       n.is_read as isRead
 from notification n
   where n.fk_user_id =10
    UNION select a.id, a.body as body, date_format(a.created_at,'%Y-%m-%d') as acreatedAt2, a.role as role,
            CASE WHEN a.alarm_is_read = 1
            THEN 'true'
            WHEN a.alarm_is_read = 0 THEN 'false'
            ELSE false
            END
  from  alarm a
where a.role in(1)