[fix] Spring Boot Data JPA - No identifier specified for entity

If you are using Spring Boot + Spring Data or JPA and you get the below exception,

Exception Stack:
Caused by: org.hibernate.AnnotationException: No identifier specified for entity: 
        at org.hibernate.cfg.InheritanceState.determineDefaultAccessType(InheritanceState.java:264) 
        at org.hibernate.cfg.InheritanceState.getElementsToProcess(InheritanceState.java:209) 
        at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:676)


As you can read from the Stacktrace that it is an AnnotationException, so either you have missed adding @ID annotation to your entity or you have made use of the wrong @ID import.


Replace: import org.springframework.data.annotation.Id; with import jakarta.persistence.Id;

Spring Boot Fix - No identifier specified for entity exception

Have Questions? Post them here!
Try Out Code2care Dev Tools:


Code2care is an initiative to publish and share varied knowledge in programming and technical areas gathered during day-to-day learnings and development activities.

Students and software developers can leverage this portal to find solutions to their various queries without re-inventing the wheel by referring to our easy to understand posts. Technical posts might include learnings, tutorials, trouble-shooting steps, video tutorials, code snippets, how-to, blogs, articles, etc.

🎉 We are celebrating the 10th years of Code2care! Thank you for all your support!

We strongly support Gender Equality & Diversity.