[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: 
org.code2care.todolist.todolist.entities.ToDoEntity
        at org.hibernate.cfg.InheritanceState.determineDefaultAccessType(InheritanceState.java:264) 
~[hibernate-core-6.1.1.Final.jar:6.1.1.Final]
        at org.hibernate.cfg.InheritanceState.getElementsToProcess(InheritanceState.java:209) 
~[hibernate-core-6.1.1.Final.jar:6.1.1.Final]
        at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:676)
 ~[hibernate-core-6.1.1.Final.jar:6.1.1.Final]
 


Reason:

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.



Fix:

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



Spring Boot Fix - No identifier specified for entity exception


Facing issues? Have Questions? Post them here! I am happy to answer!

Author Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail: rakesh@code2care.org



















Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap