728x90
에러로그
: 포스트맨에서 다음과 같은 에러가 발생한다면, 대부분 쿼리문제다
/* 포스트맨 */
invaliddataaccessapiusageexception
/* IDEA 로그 */
sql error: 1049, sqlstate: 42000
원인
쿼리문제다.
쿼리가 있는 부분은 전부 의심해보자.
해결방법
1. 쿼리메소드를 잘못 작성했을 수 있다.
가령, 아래와 같은 예시가 있다. 위가 틀린 예, 아래가 올바른 예 이다.
아마, Column을 찾을 수 없다고 나올 것이다. SELECT 문을 주의하자
@Query(value = "SELECT topic FROM Topic topic WHERE topic.MEMBER_ID =:memberId", nativeQuery = true)
Page<Topic> findAllByMemberIdOrderByCreatedAtDesc(@Param("memberId") Long memberId, Pageable pageable);
@Query(value = "SELECT * FROM Topic topic WHERE topic.MEMBER_ID =:memberId", nativeQuery = true)
Page<Topic> findAllByMemberIdOrderByCreatedAtDesc(@Param("memberId") Long memberId, Pageable pageable);
2. 때려죽여도 쿼리 메소드는 잘 짰다. 그럼 뭐가 문제일까? : data.sql을 확인해보자.
필자의 경우, 더미데이터를 잘못짰다.
정확히는 덜 짰다.
확인하고자 하는 더미데이터 외에 연관된 하위 더미데이터를 작성하지 않아, 올바른 쿼리가 정상 동작하지 못한 것이다.
위쪽이 틀린 예, 아래쪽인 올바른 예 이다.
INSERT INTO Topic(topicId, createdAt, last_modified_at, category, closedAt, content, title, topicStatus, MEMBER_ID) VALUES
(1, '2023-01-01 00:05:33.825730', '2023-01-01 00:05:33.825730', 'Food', '2023-02-28 00:05:30.000000', '상세내용', '제목', 'ACTIVE', 1);
INSERT INTO Topic(topicId, createdAt, last_modified_at, category, closedAt, content, title, topicStatus, MEMBER_ID) VALUES
(1, '2023-01-01 00:05:33.825730', '2023-01-01 00:05:33.825730', 'Food', '2023-02-28 00:05:30.000000', '상세내용', '제목', 'ACTIVE', 1);
INSERT INTO TopicVoteItem(topicVoteItemId, createdAt, last_modified_at, topicVoteItemName, topic_id) VALUES
(1,'2023-01-01 00:05:33.825730','2023-01-01 00:05:33.825730', '투표 게시글 투표 항목1 테스트',1),
(2,'2023-01-01 00:05:33.825730','2023-01-01 00:05:33.825730', '투표 게시글 투표 항목2 테스트',1);
728x90
'Java & Spring > Error' 카테고리의 다른 글
| [Error] Google OAuth 2.0 로그인 API 동작 중, "액세스 차단됨: 이 앱의 요청이 잘못되었습니다"오류 (0) | 2023.06.05 |
|---|---|
| [Error] Google OAuth 2.0 로그인 중 Whitelabel Error Page (0) | 2023.06.05 |
| [에러로그] org.hibernate.QueryException: Named parameter not bound (0) | 2023.01.27 |
| [에러로그] JpaSystemException - 원인 : GenerateValue (2) | 2023.01.24 |
| [Ngrok] Cors 이슈 해결하기 (0) | 2022.12.03 |