Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Data JPA Immutable Entity

Using Spring Data JPA with Hibernate, are these two annotations interchangeable?

  1. org.hibernate.annotations.Immutable
  2. org.springframework.data.annotation.Immutable

More specifically, can the Spring annotation replace the Hibernate annotation, to avoid any direct Hibernate dependency in the entity? If not, is there any reason to have both annotations on the same entity?

like image 952
jaco0646 Avatar asked May 29 '26 18:05

jaco0646


1 Answers

No, they are not interchangeable.

For Hibernate you need to use the Hibernate one.

If you use Spring Data modules except Spring Data JPA, i.e. those where Spring Data does the persisting itself you need to use the Spring Data annotation.

In both cases the other annotation will be completely ignored.

like image 74
Jens Schauder Avatar answered Jun 01 '26 16:06

Jens Schauder