question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Row is always updated when using JSON objects wrapped in POJOs with no explicit equals method

See original GitHub issue

Hello,

I am using PostgreSQL database and have a table with some jsonb data. I am using JsonBinaryType from hibernate-types-52 to map jsonb to POJO property in my entity.

@Entity
@TypeDef(name = "jsonb", typeClass = JsonBinaryType.class)
public class InstrumentEntity{
    ....
    @Type(type = "jsonb")
    @Column(name = "instrument_configuration", columnDefinition = "jsonb")
    private InstrumentConfiguration configuration;
    ....
}

My problem is the following, even when I am only trying to fetch (read) the entity from the database and don’t update anything in it, when my transaction finishes, hibernate performs a row update! I know this because I see it in PostgreSQL log. This is really unexpected and causes performance regression and even deadlocks in my application.

How to avoid performing row updates when I only want to fetch the data? If no JsonBinaryType is used, row is only updated if I update the entity, as expected.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:17 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
vladmihalceacommented, Mar 21, 2020

I managed to replicate it and this commit fixes the issue. This fix will be included in 2.9.7, but I will wait for one or two more fixes or improvements to release that.

You should give it a try and see if it works for you too. You can build the hibernate-types-52 without running the tests and use the 2.9.7-SNAPSHOT artifact to validate the fix.

1reaction
vladmihalceacommented, Jan 5, 2022

I’m glad I could help

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jackson: How to add custom property to the JSON without ...
Simply wrap the POJO in a MorphedResult, and then add or remove properties at will. When serialized, the MorphedResult wrapper disappears and any...
Read more >
Hibernate ORM 5.4.33.Final User Guide - Red Hat on GitHub
Hibernate not only takes care of the mapping from Java classes to database ... while the wrap method is used to transform the...
Read more >
POJO Data Binding Interface (Java Application Developer's ...
The Data Bind interface is intended for use in situations where the in-database representation of objects is not as important as using a...
Read more >
JSONObject - Android Developers
Creates a new JSONObject with name/value mappings from the JSON string. ... If the object is a JSONArray or JSONObject , no wrapping...
Read more >
ItemReaders and ItemWriters - Spring
An item might represent a line in a file, a row in a database, or an element ... Spring Batch begins the process...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found