Skip to content

Comments

[REFACTOR] ItemRepository 쿼리문 수정#145

Closed
e2guana wants to merge 2 commits intodevfrom
refactor/144-query
Closed

[REFACTOR] ItemRepository 쿼리문 수정#145
e2guana wants to merge 2 commits intodevfrom
refactor/144-query

Conversation

@e2guana
Copy link
Contributor

@e2guana e2guana commented Dec 14, 2025

🎋 이슈 및 작업중인 브랜치

#144
#140 에서 추가한 itemrepository 내 쿼리문 컬럼 이름 이슈로 검색 시 에러발생하여 수정
image

🔑 주요 내용

Check List

  • Reviewers 등록을 하였나요?
  • Assignees 등록을 하였나요?
  • 라벨(Label) 등록을 하였나요?
  • PR 머지하기 전 반드시 CI가 정상적으로 작동하는지 확인해주세요!

Summary by CodeRabbit

  • Bug Fixes
    • Corrected query logic that affected item searches and the exclusion of blocked users so results and counts now accurately reflect block relationships.
    • Adjusted related query formatting to ensure consistent behavior across nearby, keyword, filtered searches and their count results.

✏️ Tip: You can customize this high-level summary in your review settings.

@e2guana e2guana self-assigned this Dec 14, 2025
@e2guana e2guana added the 🔨RAFACTOR 리팩토링 관련 label Dec 14, 2025
@coderabbitai
Copy link

coderabbitai bot commented Dec 14, 2025

Walkthrough

ItemRepository queries were updated to replace entity-based JPQL references with concrete table/column names: i.selleri.seller_id, BlockListblock_list, blockerblocker_id, and blockedblocked_user_id across multiple search and count queries.

Changes

Cohort / File(s) Change Summary
Database column/table reference updates
src/main/java/com/salemale/domain/item/repository/ItemRepository.java
Replaced entity/field references in multiple JPQL/native queries (findNearbyItems, searchItemsByKeyword, searchItemsByKeywordWithFilters, searchItemsByFiltersOnly, findNearbyItemsByKeyword and their count variants) to use table/column names: block_list, blocker_id, blocked_user_id, seller_id. Minor formatting/parenthesis alignment adjusted; a possible stray token ("g)") noted in a count query.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Check for the stray "g)" artifact in the count query.
  • Verify column/table names match the actual DB schema and mapping (seller_id, blocker_id, blocked_user_id).
  • Confirm all updated queries compile and produce equivalent semantics in JPQL vs. native SQL contexts.

Possibly related issues

Possibly related PRs

Suggested reviewers

  • nomorefifa
  • beans3142

Poem

🐇 In code I hop where queries hide,
I swap the names and smooth the stride,
seller_id and blocker_id align,
blocked_user_id now reads just fine,
A tiny hop — the DB sings with pride.

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title '[REFACTOR] ItemRepository 쿼리문 수정' directly describes the main change—fixing query column names in ItemRepository to resolve search errors.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch refactor/144-query

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (3)
src/main/java/com/salemale/domain/item/repository/ItemRepository.java (3)

116-138: Critical: JPQL query using native SQL column/table names will fail at runtime.

This is a JPQL query (no nativeQuery = true), but it references native SQL identifiers (i.seller_id, block_list, bl.blocker_id, bl.blocked_user_id). JPQL requires entity field names, not database column names.

Apply this diff to use proper JPQL syntax:

     @Query("""
             SELECT i FROM Item i
             WHERE i.itemType = com.salemale.global.common.enums.ItemType.AUCTION
               AND i.itemStatus = :status
               AND (
-                   :me IS NULL OR i.seller_id NOT IN (
-                       SELECT bl.blocked_user_id
-                       FROM block_list bl
-                       WHERE bl.blocker_id = :me
+                   :me IS NULL OR i.seller.id NOT IN (
+                       SELECT bl.blocked.id
+                       FROM BlockList bl
+                       WHERE bl.blocker.id = :me
                    )
                )
               AND (
                 LOWER(i.title) LIKE LOWER(CONCAT('%', :keyword, '%'))
                  OR LOWER(i.name) LIKE LOWER(CONCAT('%', :keyword, '%'))
               )
             ORDER BY i.createdAt DESC
             """)

Note: Verify the exact field names in BlockList entity (e.g., blocked, blocker) match your entity definition.


146-181: Critical: Same JPQL/native SQL mismatch issue.

This JPQL query also incorrectly uses native SQL column/table names.

Apply this diff:

     @Query("""
             SELECT i FROM Item i
             WHERE i.itemType = com.salemale.global.common.enums.ItemType.AUCTION
               AND i.itemStatus = :status
               AND (
-                    :me IS NULL OR i.seller_id NOT IN (
-                        SELECT bl.blocked_user_id
-                        FROM block_list bl
-                        WHERE bl.blocker_id = :me
+                    :me IS NULL OR i.seller.id NOT IN (
+                        SELECT bl.blocked.id
+                        FROM BlockList bl
+                        WHERE bl.blocker.id = :me
                     )
                 )

189-219: Critical: Same JPQL/native SQL mismatch issue.

This JPQL query also incorrectly uses native SQL column/table names.

Apply this diff:

     @Query("""
             SELECT i FROM Item i
             WHERE i.itemType = com.salemale.global.common.enums.ItemType.AUCTION
               AND i.itemStatus = :status
               AND (
-                   :me IS NULL OR i.seller_id NOT IN (
-                       SELECT bl.blocked_user_id
-                       FROM block_list bl
-                       WHERE bl.blocker_id = :me
+                   :me IS NULL OR i.seller.id NOT IN (
+                       SELECT bl.blocked.id
+                       FROM BlockList bl
+                       WHERE bl.blocker.id = :me
                    )
                )
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0149872 and 26bd928.

📒 Files selected for processing (1)
  • src/main/java/com/salemale/domain/item/repository/ItemRepository.java (7 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
🔇 Additional comments (2)
src/main/java/com/salemale/domain/item/repository/ItemRepository.java (2)

63-68: LGTM!

Native SQL queries correctly use database column names (seller_id, blocked_user_id, blocker_id) and table name (block_list). This is the appropriate syntax for nativeQuery = true.

Also applies to: 87-92


231-236: LGTM!

Native SQL syntax is correctly applied for this native query.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (2)
src/main/java/com/salemale/domain/item/repository/ItemRepository.java (2)

151-156: Critical: JPQL query uses SQL column names instead of entity properties.

This JPQL query incorrectly uses SQL column names (i.seller_id, block_list, bl.blocker_id, bl.blocked_user_id) instead of entity property navigation, which will cause a runtime error.

Apply this diff to use correct JPQL entity navigation:

               AND (
-                    :me IS NULL OR i.seller_id NOT IN (
-                        SELECT bl.blocked_user_id
-                        FROM block_list bl
-                        WHERE bl.blocker_id = :me
+                    :me IS NULL OR i.seller.id NOT IN (
+                        SELECT bl.blocked.id
+                        FROM BlockList bl
+                        WHERE bl.blocker.id = :me
                     )
                 )

Note: Adjust bl.blocked.id to match your BlockList entity's property name for the blocked user.


194-199: Critical: JPQL query uses SQL column names instead of entity properties.

This JPQL query incorrectly uses SQL column names instead of entity property navigation, which will cause a QuerySyntaxException at runtime.

Apply this diff to use correct JPQL entity navigation:

               AND (
-                   :me IS NULL OR i.seller_id NOT IN (
-                       SELECT bl.blocked_user_id
-                       FROM block_list bl
-                       WHERE bl.blocker_id = :me
+                   :me IS NULL OR i.seller.id NOT IN (
+                       SELECT bl.blocked.id
+                       FROM BlockList bl
+                       WHERE bl.blocker.id = :me
                    )
                )

Note: Adjust bl.blocked.id to match your BlockList entity's property name for the blocked user.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 26bd928 and e964603.

📒 Files selected for processing (1)
  • src/main/java/com/salemale/domain/item/repository/ItemRepository.java (8 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
🔇 Additional comments (2)
src/main/java/com/salemale/domain/item/repository/ItemRepository.java (2)

63-68: LGTM! Native SQL syntax is correct.

The block-list subquery correctly uses table and column names (block_list, blocker_id, blocked_user_id) appropriate for native SQL.

Also applies to: 87-92


231-236: LGTM! Native SQL syntax is correct.

The block-list subquery correctly uses table and column names appropriate for native SQL. The previously reported typo on line 264 appears to have been resolved.

Also applies to: 259-264

@e2guana e2guana closed this Dec 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🔨RAFACTOR 리팩토링 관련

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants