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.

Dirty Checking on Map for HStore Type

See original GitHub issue

Hi,

I have an HStore typed Map<String,String> for hibernate5 module.

if I only update the content of the map, the entity is not dirty tracked and appears clean, and is not persisted on update.

I’ve tried to add this scenario to the test case for this hibernate v5 module but I can’t get the repo to compile as-is (mvn toolchains and other dependencies not found)

The hashCode and equals on my entity works fine - I have tests that demonstrates hashcode changes upon map content changes and equals also breaks when only the map changes.

As a workaround, I have the following Entity property

@Entity
public class MyEntity {
   ...
   private int version;
   // getters and setters omitted.  Note this does not use the @Version annotation.
}

Then (As I’m doing my own audit logging, I know when a change has occurred I can do the following:

if ( mergeUpdated ) {
    myEntity.setVersion(myEntity.getMapProp().hashcode());
}

This statement makes the entity itself dirty and is persisted as expected.

I don’t know if this is something that can be adjusted by this library? I’ve no idea how much of hibernate’s instrumentation is in the Map implementation it provides after loading an entity and whether or not that can be forced to check a different way.

Thanks

Rob

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
vladmihalceacommented, Jun 27, 2022

Sure thing. Check out this article.

0reactions
vladmihalceacommented, Jun 27, 2022

No worries. In the meanwhile, you could switch to a jsonb column and persist the Map attribute to it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

automatic dirty checking not working on array type #106 - GitHub
In a grails app I have a domain class like this: class User ... I have observed the same missing drty-checking on Map...
Read more >
Documentation: 15: F.18. hstore - PostgreSQL
This module implements the hstore data type for storing sets of key/value pairs within a single PostgreSQL value. This can be useful in...
Read more >
ActiveModel::Dirty - Rails API
Active Model Dirty Provides a way to track changes in your object in the same way as Active Record does.
Read more >
Mapping multiple JPA entities to one database table
Using multiple entities can speed up both read and write operations. ... And the Hibernate dirty checking mechanism will detect the change ...
Read more >
ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Hstore
Class: Active Record:: Connection Adapters:: Postgre SQL:: OID:: Hstore. Do not use. ... Determines whether a value has changed for dirty checking.
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