Skip to content

Conversation

@RCNR
Copy link
Contributor

@RCNR RCNR commented Aug 15, 2025

📍 PR 타입 (하나 이상 선택)

  • 기능 추가
  • 버그 수정
  • 의존성, 환경 변수, 빌드 관련 코드 업데이트
  • 기타 사소한 수정

📌 개요

  • 기존 identity에서 sequence로의 변경

🔁 변경 사항

📸 스크린샷

✅ 체크리스트

  • 코드가 정상적으로 동작하는지 확인
  • PR에 적절한 라벨을 선택
  • 관련 테스트 코드 작성
  • 문서(README, Swagger 등) 업데이트

💡 추가 사항 (리뷰어가 참고해야 할 것)

Summary by CodeRabbit

  • Refactor
    • Updated internal identifier generation strategy for stock data records to enhance consistency across environments.
  • Chores
    • Standardized persistence configuration for stock data, aligning settings across related records.
    • Performed minor import and code cleanup with no functional impact.
  • Notes
    • No user-facing changes.

- 기존 identity에서 sequence로의 변경
@RCNR RCNR self-assigned this Aug 15, 2025
@coderabbitai
Copy link

coderabbitai bot commented Aug 15, 2025

Walkthrough

Switches JPA ID generation for two stock entity classes from IDENTITY to SEQUENCE with named generators and allocationSize=50, and consolidates persistence imports to jakarta.persistence.*. No other fields or behaviors changed.

Changes

Cohort / File(s) Summary
Sequence-based ID generation + import consolidation
src/main/java/naughty/tuzamate/domain/stock/entity/KrxStockInfo.java, src/main/java/naughty/tuzamate/domain/stock/entity/NasdaqStockInfo.java
Replaced GenerationType.IDENTITY with GenerationType.SEQUENCE using named @SequenceGenerator (allocationSize=50) and updated @GeneratedValue to reference the generator; consolidated multiple jakarta.persistence imports into a wildcard.

Sequence Diagram(s)

sequenceDiagram
    participant App as Application
    participant EM as JPA EntityManager
    participant DB as Database (Sequence)

    App->>EM: persist(Entity)
    EM->>DB: SELECT nextval('..._stock_info_seq')
    DB-->>EM: sequence value
    EM->>DB: INSERT into table with generated ID
    DB-->>EM: insert OK
    EM-->>App: managed entity with ID
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~7 minutes

Poem

A hop, a skip—new IDs in a row,
Sequences spring where once streams flowed slow.
Fifty in a basket, ready to go—
I stamp each stock with a bunny’s glow.
Thump! Commit. And off we go! 🐇✨

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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

🧹 Nitpick comments (4)
src/main/java/naughty/tuzamate/domain/stock/entity/KrxStockInfo.java (1)

3-3: Prefer explicit JPA imports over wildcard.

Improves readability and keeps Checkstyle/IDE settings happy in many codebases.

Apply this diff:

-import jakarta.persistence.*;
+import jakarta.persistence.Entity;
+import jakarta.persistence.GeneratedValue;
+import jakarta.persistence.GenerationType;
+import jakarta.persistence.Id;
+import jakarta.persistence.SequenceGenerator;
src/main/java/naughty/tuzamate/domain/stock/entity/NasdaqStockInfo.java (3)

14-20: Confirm matching DB sequence and migration exist for nasdaq_stock_info_seq.

Same concerns as KRX: DB support, sequence creation, increment, and initialization to avoid PK conflicts with existing rows.

If using Postgres:

CREATE SEQUENCE IF NOT EXISTS nasdaq_stock_info_seq INCREMENT BY 50;
SELECT setval('nasdaq_stock_info_seq', GREATEST((SELECT COALESCE(MAX(id),0) FROM nasdaq_stock_info), 1), true);

I can add Flyway migrations if you’d like.


3-3: Avoid wildcard JPA import for consistency.

Apply this diff:

-import jakarta.persistence.*;
+import jakarta.persistence.Entity;
+import jakarta.persistence.GeneratedValue;
+import jakarta.persistence.GenerationType;
+import jakarta.persistence.Id;
+import jakarta.persistence.SequenceGenerator;

19-19: Minor: align comment style on allocationSize with KRX file or remove both.

KRX includes a Korean inline comment explaining the 50-ID pool; this file doesn’t. Consider adding a brief comment here or removing in both for consistency.

-            allocationSize = 50
+            allocationSize = 50 // pre-allocate 50 IDs for batching
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 9372a9e and f6074bd.

📒 Files selected for processing (2)
  • src/main/java/naughty/tuzamate/domain/stock/entity/KrxStockInfo.java (2 hunks)
  • src/main/java/naughty/tuzamate/domain/stock/entity/NasdaqStockInfo.java (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
src/main/java/naughty/tuzamate/domain/stock/entity/KrxStockInfo.java (3)
src/main/java/naughty/tuzamate/domain/stock/repository/KrxStockInfoRepository.java (1)
  • KrxStockInfoRepository (6-7)
src/main/java/naughty/tuzamate/domain/stock/entity/StockCode.java (1)
  • StockCode (10-24)
src/main/java/naughty/tuzamate/domain/stock/dto/krx/KrxDto.java (1)
  • KrxStockInfoDto (39-62)
src/main/java/naughty/tuzamate/domain/stock/entity/NasdaqStockInfo.java (3)
src/main/java/naughty/tuzamate/domain/stock/dto/nasdaq/NasdaqDto.java (1)
  • NasdaqInfoDto (10-33)
src/main/java/naughty/tuzamate/domain/stock/repository/NasdaqStockInfoRepository.java (1)
  • NasdaqStockInfoRepository (6-7)
src/main/java/naughty/tuzamate/domain/savings/entity/Savings.java (1)
  • Savings (6-35)
🔇 Additional comments (3)
src/main/java/naughty/tuzamate/domain/stock/entity/KrxStockInfo.java (2)

14-20: Good call switching to SEQUENCE — unlocks batching and better insert throughput.

Moving off IDENTITY allows Hibernate to pre-allocate IDs and batch inserts effectively. The dedicated generator per-entity is also a clean separation.


19-19: allocationSize=50: ensure DB sequence increment matches for optimal performance.

For Hibernate’s pooled optimizer to be effective (and to avoid warnings), set the DB sequence INCREMENT BY 50. Otherwise you’ll still work correctly but incur extra sequence calls and see larger gaps on restarts.

Example (Postgres):

ALTER SEQUENCE krx_stock_info_seq INCREMENT BY 50;
src/main/java/naughty/tuzamate/domain/stock/entity/NasdaqStockInfo.java (1)

14-20: SEQUENCE strategy looks good and consistent with KRX.

Dedicated sequence and generator name mirror KrxStockInfo and enable batching.

Comment on lines +14 to +20
@GeneratedValue(strategy = GenerationType.SEQUENCE,
generator = "krx_stock_info_seq")
@SequenceGenerator(
name = "krx_stock_info_seq",
sequenceName = "krx_stock_info_seq",
allocationSize = 50 // 시퀀스 한 번에 50개 id 확보
)
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Verify DB dialect and add DB migrations for the sequence (prod/staging).

SEQUENCE requires DB support and presence of the named sequence. If you’re on MySQL, this will break; if Postgres/Oracle, add migrations to create and initialize the sequence(s) accordingly. Also ensure start value ≥ max(id)+1 to avoid PK collisions on existing tables.

Run the following to verify DB dialect and presence of sequence migrations:

If you’re on Postgres, a Flyway SQL example:

-- Vxxx__create_stock_sequences.sql
CREATE SEQUENCE IF NOT EXISTS krx_stock_info_seq INCREMENT BY 50;
SELECT setval('krx_stock_info_seq', GREATEST((SELECT COALESCE(MAX(id),0) FROM krx_stock_info), 1), true);

CREATE SEQUENCE IF NOT EXISTS nasdaq_stock_info_seq INCREMENT BY 50;
SELECT setval('nasdaq_stock_info_seq', GREATEST((SELECT COALESCE(MAX(id),0) FROM nasdaq_stock_info), 1), true);

If on Oracle:

BEGIN
  EXECUTE IMMEDIATE 'CREATE SEQUENCE krx_stock_info_seq INCREMENT BY 50 START WITH 1';
EXCEPTION WHEN OTHERS THEN IF SQLCODE != -955 THEN RAISE; END IF; END;
/
BEGIN
  EXECUTE IMMEDIATE 'CREATE SEQUENCE nasdaq_stock_info_seq INCREMENT BY 50 START WITH 1';
EXCEPTION WHEN OTHERS THEN IF SQLCODE != -955 THEN RAISE; END IF; END;
/

If on MySQL/MariaDB: SEQUENCE is not supported in MySQL (and differs in MariaDB). You’ll need IDENTITY or TABLE generator there. I can generate the required DB-specific migrations or revert strategy if needed.


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== Checking DB dialect config (application.*) =="
fd -a 'application.*' src/main/resources | xargs -r -I{} sh -c 'echo "-- {} --"; rg -n -C2 -e "spring.datasource.url|spring.jpa.database-platform|hibernate.dialect" "{}" || true'

echo
echo "== Stock entities using @GeneratedValue strategies =="
rg -nP -C3 --glob 'src/main/java/**/domain/stock/entity/**' '@GeneratedValue\s*\(.*?GenerationType\.\w+'

echo
echo "== Migration scripts referencing the new sequences =="
rg -n -C2 -e 'create sequence|alter sequence|setval|krx_stock_info_seq|nasdaq_stock_info_seq' --hidden

Length of output: 415


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== Repo top-level =="
ls -la

echo
echo "== Find application.* files =="
fd -a 'application.*' || true

echo
echo "== Search for Spring DB / Hibernate config in repository =="
rg -nS --hidden -e 'spring\.datasource|spring\.jpa|hibernate\.dialect|spring\.datasource\.url|spring\.jpa\.database-platform' || true

echo
echo "== Search for GenerationType.SEQUENCE / @SequenceGenerator / @GeneratedValue usages =="
rg -nP --hidden -C3 -e 'GenerationType\.SEQUENCE|@SequenceGenerator|@GeneratedValue' || true

echo
echo "== Search for migration SQL referencing sequences =="
rg -nS --hidden -e 'krx_stock_info_seq|create sequence|CREATE SEQUENCE|setval|alter sequence' || true

echo
echo "== Locate KrxStockInfo.java and show its top 200 lines if present =="
file_path=$(rg -n --hidden -S -g '!**/target/**' 'class\s+KrxStockInfo' | sed -n '1s/:.*//p' || true)
if [ -n "$file_path" ]; then
  echo "-- $file_path --"
  sed -n '1,200p' "$file_path"
else
  echo "KrxStockInfo.java not found"
fi

Length of output: 11556


Add DB migrations for SEQUENCE-based IDs or switch to a DB-compatible strategy

Quick summary: I verified the repo — two entities use GenerationType.SEQUENCE but there are no DB dialect/config entries or migration scripts creating those sequences. This will fail on MySQL (which lacks SEQUENCE) and will still require explicit sequence creation on Postgres/Oracle to avoid PK collisions.

Files needing attention:

  • src/main/java/naughty/tuzamate/domain/stock/entity/KrxStockInfo.java — generator "krx_stock_info_seq"
  • src/main/java/naughty/tuzamate/domain/stock/entity/NasdaqStockInfo.java — generator "nasdaq_stock_info_seq"

Verification notes:

  • No occurrences of spring.datasource / spring.jpa / hibernate.dialect were found in the repo (no explicit DB dialect/config detected).
  • No migration SQL referencing krx_stock_info_seq / nasdaq_stock_info_seq (CREATE SEQUENCE / setval / ALTER SEQUENCE) detected.

Actionable fixes (pick one):

  • If you use Postgres/Oracle: add migrations to create the sequences and set their current values >= MAX(id)+1. Example Flyway SQL for Postgres:
    -- Vxxx__create_stock_sequences.sql
    CREATE SEQUENCE IF NOT EXISTS krx_stock_info_seq INCREMENT BY 50;
    SELECT setval('krx_stock_info_seq', GREATEST((SELECT COALESCE(MAX(id),0) FROM krx_stock_info)+1, 1), true);
    CREATE SEQUENCE IF NOT EXISTS nasdaq_stock_info_seq INCREMENT BY 50;
    SELECT setval('nasdaq_stock_info_seq', GREATEST((SELECT COALESCE(MAX(id),0) FROM nasdaq_stock_info)+1, 1), true);
  • If you use MySQL/MariaDB: SEQUENCE is unsupported — change entities to GenerationType.IDENTITY (or use a TABLE generator / application-side id allocation) instead.
  • Ensure allocationSize (50) matches the sequence INCREMENT BY and that the migration start value prevents PK collisions.

Please add the migrations (or change the generation strategy) and ensure they are applied in prod/staging.

🤖 Prompt for AI Agents
In src/main/java/naughty/tuzamate/domain/stock/entity/KrxStockInfo.java (lines
~14-20) and
src/main/java/naughty/tuzamate/domain/stock/entity/NasdaqStockInfo.java, the
entities use GenerationType.SEQUENCE with named generators ("krx_stock_info_seq"
/ "nasdaq_stock_info_seq") but the repo has no DB dialect config or migration
scripts to create those sequences; either add DB migrations for your chosen DB
(e.g., Flyway/V1__create_stock_sequences.sql that creates the two sequences with
INCREMENT BY matching allocationSize and sets their start values >= MAX(id)+1)
if using Postgres/Oracle, or change the entities to a DB-compatible strategy
such as GenerationType.IDENTITY (or TABLE generator/application id allocation)
if using MySQL/MariaDB; also ensure allocationSize (50) matches the sequence
INCREMENT BY in the migration to avoid PK collisions and apply these migrations
in prod/staging.

@RCNR
Copy link
Contributor Author

RCNR commented Aug 15, 2025

MySQL은 sequence 전략이 적용되지 않아 PR 필요없다

@RCNR RCNR closed this Aug 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant