Home > front end >  Stop increasing of hibernate version column as child is not modified
Stop increasing of hibernate version column as child is not modified

Time:07-23

I have two entities which have one-to-one relationship Site and Address. Both the tables have hibernate version column. i am using sitedao.save(siteEntity) to save, which saves both site and address.

When I am performing an update operation on site entity fields and persist, both site and address entity versions are getting updated because of @UpdateTimestamp annotation on lastModifiedAt column in the address table. This column makes the row dirty and increases the version column data (lastModifiedAt is coming from BaseEntity)

How can we avoid version increment in the address column

CodePudding user response:

You could remove the CascadeType.MERGE between them, and save these two entities separately. Then you could make a query to check if new address is different from the old one and only then save the address to update its version.

CodePudding user response:

I got this solution from the below link. https://docs.jboss.org/hibernate/orm/6.0/userguide/html_single/Hibernate_User_Guide.html#locking-optimistic setting this annotation @OptimisticLock(excluded = true) on lastModifiedAt column solve this issue.

  • Related