PostgreSQL 9.4 Text array Always Update Database with Hibernate 5.2

Sajith vijesekara
2 min readNov 13, 2019

This issue was happens in last month when we testing some feature in postgres database . We have Two tables called “PRODUCT” and “PURCHASE” in database.when we trying to save purchase record in database what it does is retrieve the products from product data & calculate the purchase order & save the record in database table. Then suddenly we saw that there is always product Update query fired to database when we do the purchase . Fundamentally we only retrieve the product not update those data. Then we went through code line by line and try to find out the issue . Code base seems working fine . No Database update for products .

The next step is to debug the code before that we went through the postgres logs and try to find out issue. But the problem is in database update it shows that table update query updates all the fields in table . To find out what is the exact update field I have used @DynamicUpdate to see the actual sql update query.

Then It shows one column always update even if there are no update available which datatype is “TEXT ARRAY

Identify the Issue

For Mapping Postgres Text Array to Hibernate Text Array We have added this class.

Then We figure It out that this class what it does is it always check is there difference in StringArrayType Objects if it is available it send Update request to database.

Solution

Remove Above Class & Add following library which resolve the issue

<dependency>
<groupId>com.vladmihalcea</groupId>
<artifactId>hibernate-types-52</artifactId>
<version>${hibernate-types.version}</version>
</dependency>

This HibernateTyps Library support for Enum Array , Integer Array , String Array , Json Array & other Array Types.

Thanks

--

--

Sajith vijesekara

Technical Lead. Passionate about cloud computing & web security | Freelance Mobile Developer| CKAD | AWS Community Builder 🇱🇰