JSON objects are not marked as dirty when modified

Hello,
Similar to HHH-16682, we’re running into an issue where changes to a nested JSON object stored as a JSON string and annotated with @JdbcTypeCode(SqlTypes.JSON) do not mark the parent entity as dirty when modified. Our existing DB tables store the objects as JSON strings, and we’d like to avoid schema changes.

Our use case is identical to the one described in the issue, except for the fact that our MyJson class is not marked as Embeddable, e.g. modifying MyJson.stringProp will not cause MyEntity to be marked as dirty. It also appears this is deliberate or a known issue based on the description in HHH-16774.

Is there a way for us to take advantage of the built-in JSON type, or some other way to indicate that Hibernate should track the nested entity?

We’re on org.hibernate.orm:hibernate-core version 6.2.7.Final for reference

public class MyEntity {
    @Id
    private Long id;
    @JdbcTypeCode(SqlTypes.JSON)
    private MyJson jsonProperty;
    private String info;
  }

public class MyJson {
    private String stringProp;
    private Long longProp;
}

cc @beikov since looks like you have the most context based on two linked tickets

Try updating to the latest version, and if the problem persists, please create an issue in the issue tracker(https://hibernate.atlassian.net) with a test case(https://github.com/hibernate/hibernate-test-case-templates/blob/master/orm/hibernate-orm-6/src/test/java/org/hibernate/bugs/JPAUnitTestCase.java) that reproduces the issue.

@beikov Created a test reproducing the issue on hibernate-orm - [HHH-17294] Test verifying Non-Embeddable JSON objects are not marked as dirty when modified by ElTav · Pull Request #7411 · hibernate/hibernate-orm · GitHub

1 Like