Skip to content

fix: Add @Id annotation to Problem record id field - #136

Open
Rohit-code07 wants to merge 2 commits into
hardikxk:masterfrom
Rohit-code07:master
Open

fix: Add @Id annotation to Problem record id field#136
Rohit-code07 wants to merge 2 commits into
hardikxk:masterfrom
Rohit-code07:master

Conversation

@Rohit-code07

Copy link
Copy Markdown

Fix: Add Missing @Id Annotation in Problem Record

Issue Description

The Problem record in problems-service was missing the @Id annotation on its id field. Since Spring Data relies on @Id to identify the primary key, the absence of this annotation could prevent proper entity identification and affect repository operations.

Root Cause

Unlike UserProblem, which correctly defines the identifier field using @Id, the Problem record did not explicitly mark its primary key.

Before Fix

public record Problem(
    int id,
    String title,
    String acceptance,
    String difficulty
) {}

In this implementation, Spring Data cannot explicitly identify the primary key field.

Changes Made

Added the missing @Id annotation to the id field in Problem.java.

After Fix

import org.springframework.data.annotation.Id;

public record Problem(
    @Id int id,
    String title,
    String acceptance,
    String difficulty
) {}

Impact

  • Enables Spring Data to correctly recognize the primary key field
  • Improves repository behavior for operations such as findById()
  • Ensures consistent entity mapping and avoids unexpected behavior in future database operations

Files Modified

problems-service/src/main/java/com/hardik/problemsservice/model/Problem.java

Related Issue

Fixes #130

@Rohit-code07 Rohit-code07 changed the title Add @Id annotation to Problem record id field fix: Add @Id annotation to Problem record id field May 30, 2026
@Rohit-code07

Copy link
Copy Markdown
Author

Hi @hardikxk, I have resolved the issue and submitted a PR for it. Kindly review it and merge if everything looks good. Thank you!

Removed redundant note about avoiding unnecessary dependencies and updated project status section.
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.

[Bug] Problem record missing @Id annotation — Spring Data cannot identify primary key field

1 participant