# Version automatically incrementing after entity read in Spring Boot JPA

**URL:** <https://discourse.hibernate.org/t/version-automatically-incrementing-after-entity-read-in-spring-boot-jpa/5756>\
**Category:** Hibernate ORM\
**Created:** [October 1, 2021, 12:43pm UTC](https://discourse.hibernate.org/t/version-automatically-incrementing-after-entity-read-in-spring-boot-jpa/5756 "2021-10-01T12:43:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vaibhav\_Rodage](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/vaibhav_rodage/32/1661_2.png) [@Vaibhav\_Rodage](https://discourse.hibernate.org/u/Vaibhav_Rodage)\
**Post date:** [October 1, 2021, 12:43pm UTC](https://discourse.hibernate.org/t/version-automatically-incrementing-after-entity-read-in-spring-boot-jpa/5756/1 "2021-10-01T12:43:16Z")

</div>

I have requirement to export the data stored in Oracle database using spring boot application. We are using **@Version** for maintaining version. When we get the data using entity and export in excel file, versions are automatically incremented by 1.  
As per my knowledge when we make any changes in persisted entity then it will increment the version and persist the data. But here we are getting data for read only purpose. Kindly help me trace the issue here.  
  
  
Hibernate version : 5.3.10.Final  
Spring Boot Version: 2…1.6  
  
  
**Logs while updating entity without having any changes apart from version:**  
2021-09-30 15:50:56.516 DEBUG 63898 — [http-nio-8080-exec-6] org.hibernate.SQL : `update asset set last_updated_date=?, version_no=? where record_id=? and version_no=?`  
2021-09-30 15:50:56.516 TRACE 63898 — [http-nio-8080-exec-6] o.h.type.descriptor.sql.BasicBinder : binding parameter [1] as [TIMESTAMP] - [2021-09-30T15:50:56.474]  
2021-09-30 15:50:56.516 TRACE 63898 — [http-nio-8080-exec-6] o.h.type.descriptor.sql.BasicBinder : binding parameter [2] as [BIGINT] - [8]  
2021-09-30 15:50:56.516 TRACE 63898 — [http-nio-8080-exec-6] o.h.type.descriptor.sql.BasicBinder : binding parameter [3] as [BIGINT] - [3478703]  
2021-09-30 15:50:56.516 TRACE 63898 — [http-nio-8080-exec-6] o.h.type.descriptor.sql.BasicBinder : binding parameter [4] as [BIGINT] - [7]

---

<div class="post-metadata">

**Author:** ![beikov](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/beikov/32/258_2.png) [@beikov](https://discourse.hibernate.org/u/beikov)\
**Post date:** [October 4, 2021, 10:22am UTC](https://discourse.hibernate.org/t/version-automatically-incrementing-after-entity-read-in-spring-boot-jpa/5756/2 "2021-10-04T10:22:20Z")

</div>

Maybe the timestamp changed in the meantime? Or you are facing some kind of precision mismatch? Note that `java.util.Date` is mutable, maybe you are changing the value?  
Anyway, you could detach the entity right after reading to avoid this, or clear the persistence context with `EntityManager.clear()` before this read-only transaction finishes which will detach all entities.
