Why is the version property not set with Spring Data JPA?

后端 未结 2 823
庸人自扰
庸人自扰 2020-12-16 01:23

Wanted to know how is @Version annotation in Spring Data REST put to use for ETags, I do not see the ETags populated for some reason

@Entity
@En         


        
相关标签:
2条回答
  • 2020-12-16 01:36

    I faced the same problem and after hours and hours I realized the following things that led me to the enlightenment =P

    1. Spring Data Rest provides ETag support for optimistic concurrency control ONLY after version 2.3.0. See this bug published about a year ago. Previous versions of Spring Data Rest will NOT populate the ETag header.
    2. For Spring Boot applications (our case), you need to use Spring Boot 1.3.0.BUILD-SNAPSHOT or higher in order to be able to setup a spring-boot-starter-data-rest that depends on Spring Data Rest 2.4.1 (higher than 2.3.1 which is exactly what we need :P).

    In my case I was using Spring Boot 1.2.7 and whenever I installed the spring-boot-starter-data-rest dependency I ended up getting the Spring Data Rest 2.2.0 which don't has the ETag support. After upgrading Spring Boot in my project and reinstalled the dependencies my REST API started to retrieve the ETag header =D

    0 讨论(0)
  • 2020-12-16 01:38

    With Spring Data JPA, you need to use @javax.persistence.Version. @org.springframework.data.annotation.Version is the annotation to use for other Spring Data modules.

    0 讨论(0)
提交回复
热议问题