Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'd be interested whether there is the difference between javax.persistence.Id and org.springframework.data.annotation.Id.

  1. If Spring has created that annotation only for support the JPA annotation, then why?
  2. Does org.springframework.data.annotation.Id have another [additional] purpose?
like image 735
Andrew Tobilko Avatar asked Sep 22 '16 16:09

Andrew Tobilko


People also ask

What is org Springframework data annotation ID?

org.springframework.data.annotation.Id is currently used by Spring to support mapping for other non relational persistence databases or frameworks that do not have a defined common persistence API like JPA.

What is javax persistence ID?

javax.persistenceSpecifies the primary key of an entity. The field or property to which the Id annotation is applied should be one of the following types: any Java primitive type; any primitive wrapper type; String ; java. util. Date ; java.

What is @data annotation in Spring boot?

@Data is a convenient shortcut annotation that bundles the features of @ToString , @EqualsAndHashCode , @Getter / @Setter and @RequiredArgsConstructor together: In other words, @Data generates all the boilerplate that is normally associated with simple POJOs (Plain Old Java Objects) and beans: getters for all fields, ...

What is @ID annotation in Spring boot?

The @Id annotation specifies the primary key of an entity and the @GeneratedValue provides for the specification of generation strategies for the values of primary keys.


1 Answers

org.springframework.data.annotation.Id is currently used by Spring to support mapping for other non relational persistence databases or frameworks that do not have a defined common persistence API like JPA. So, it is normally used when dealing 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. Have in mind JPA only applies for management of relational data.

like image 106
megalucio Avatar answered Oct 12 '22 18:10

megalucio