What is the difference between javax.persistence.Id and org.springframework.data.annotation.Id?

I would be wondering if there is a difference between javax.persistence.Id and org.springframework.data.annotation.Id .

  • If Spring created this annotation just to support JPA annotation, then why?
  • Is org.springframework.data.annotation.Id another [optional] purpose?
+7
java spring-data javax.persistence
source share
1 answer

org.springframework.data.annotation.Id is currently used by Spring to support matching for other databases or databases that are not related to a relational database, that do not have a specific common API, such as JPA. Thus, it is commonly used when working with other spring-data projects, such as spring-data-mongodb, spring-data-solr, etc.

javax.persistence.Id is the annotation defined by JPA for all its implementations. Keep in mind that JPA is used only for managing relational data.

+11
source share

All Articles