JPA AttributeConverter makes hibernate generate update statements on whole table in transaction
Description
Activity
Show:
![](https://secure.gravatar.com/avatar/8b9ef9aecf2d40b5f0fc6dac10abbe8f?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FHS-0.png)
Hyunsu Song December 22, 2022 at 9:25 AM
any updates on this issue? I have no idea to fix it.
I couldn’t resolve my problem even though overriding equals methods before.
These kind of issues still happens while using @Convert.
Please check this again.
![](https://secure.gravatar.com/avatar/2ea031c6c37d6f6ec9177c4561878569?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Fdefault-avatar-2.png)
Yanming Zhou (quaff@github) June 27, 2017 at 8:44 AM
My problem is resolved by override equals methods.
![](https://secure.gravatar.com/avatar/2ea031c6c37d6f6ec9177c4561878569?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Fdefault-avatar-2.png)
Yanming Zhou (quaff@github) June 27, 2017 at 7:21 AM
Confirmed with 5.1.5, It always recognized the data as dirty if AttributeConverter used. It will cause one more useless update after insert or before delete.
All code in this post can be found here: https://github.com/cuipengfei/gs-accessing-data-jpa/tree/master/complete
You can run this test to reproduce the problem: https://github.com/cuipengfei/gs-accessing-data-jpa/blob/master/complete/src/test/java/hello/T1ServiceTest.java
I have a domain model:
It has a field typed as ZonedDateTime, so I have a converter to convert it to sql time stamp:
When I try to create a lot of T1s in a transaction like this:
There will be update statements generated by hibernate for the whole t1 table.
Here is the log for the first a few rounds of the for loop:
As you can see in the log, more and more update statements will be generated by hibernate.
It looks like the number of update statements is always same as how many rows of T1 waiting to be committed.
Now if I remove the converter, this problem goes away.
I can use hibernate-java8 lib instead of this converter to achieve the same effect, but why does this happen?
Why does JPA AttributeConverter make hibernate generate update statements on whole table in transaction?