Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed JSON array is not persisted when using hibernate6 / jsonb #37184

Closed
piether opened this issue Nov 17, 2023 · 4 comments · Fixed by #36978
Closed

Changed JSON array is not persisted when using hibernate6 / jsonb #37184

piether opened this issue Nov 17, 2023 · 4 comments · Fixed by #36978
Labels
area/hibernate-orm Hibernate ORM area/persistence OBSOLETE, DO NOT USE kind/bug Something isn't working
Milestone

Comments

@piether
Copy link

piether commented Nov 17, 2023

Describe the bug

When upgrading to Quarkus 3.x, we have noticed that changes to entity properties mapped to a jsonb column in postgres were no longer picked up.

If you have a property in an entity of type TodoList:

@JdbcTypeCode(SqlTypes.JSON)
public List<Todo> todos;

and you set one of the todos to completed:

todoList.todos.get(0).completed = true;

and you then persist the entity, I expect hibernate to detect the change and write it to the db. It doesn't.

Expected behavior

When changing only the contents of a jsonb property, the system should detect the change so it will write it to the db.

Actual behavior

The change is not detected and no UPDATE statement is made. Note that if another (non-json) change is made to the entity, the json does get persisted (see second test in reproducer project).

How to Reproduce?

https://github.com/piether/quarkus-hibernate-json-bug contains a failing test

Output of uname -a or ver

Darwin V4C04H7X9R 23.1.0 Darwin Kernel Version 23.1.0: Mon Oct 9 21:27:24 PDT 2023; root:xnu-10002.41.9~6/RELEASE_ARM64_T6000 arm64

Output of java -version

openjdk version "21" 2023-09-19 OpenJDK Runtime Environment Zulu21.28+85-CA (build 21+35) OpenJDK 64-Bit Server VM Zulu21.28+85-CA (build 21+35, mixed mode, sharing)

Quarkus version or git rev

3.5.2

Build tool (ie. output of mvnw --version or gradlew --version)

Apache Maven 3.9.5 (57804ffe001d7215b5e7bcb531cf83df38f93546) Maven home: /Users/pieter/.m2/wrapper/dists/apache-maven-3.9.5-bin/32db9c34/apache-maven-3.9.5 Java version: 21, vendor: Azul Systems, Inc., runtime: /Users/pieter/.sdkman/candidates/java/21-zulu/zulu-21.jdk/Contents/Home Default locale: en_BE, platform encoding: UTF-8 OS name: "mac os x", version: "14.1", arch: "aarch64", family: "mac"

Additional information

No response

@piether piether added the kind/bug Something isn't working label Nov 17, 2023
@quarkus-bot quarkus-bot bot added area/hibernate-orm Hibernate ORM area/persistence OBSOLETE, DO NOT USE labels Nov 17, 2023
Copy link

quarkus-bot bot commented Nov 17, 2023

/cc @Sanne (hibernate-orm), @gsmet (hibernate-orm), @yrodiere (hibernate-orm)

@yrodiere
Copy link
Member

Hey,

You're saying they are "no longer" picked up, but can you detail what you were doing when they were picked up? Because persisting content as JSON was not even available in Quarkus 2.x...

Regarding the underlying problem, I wonder if deep change tracking is even supported for properties annotated with @JdbcTypeCode(SqlTypes.JSON)... Is it, @beikov?

As for workarounds, making your Todo class an embeddable and using @Struct may help, though I'm not sure at all: https://docs.jboss.org/hibernate/orm/6.2/userguide/html_single/Hibernate_User_Guide.html#_struct_aggregate_embeddable_mapping

@yrodiere yrodiere added the triage/needs-feedback We are waiting for feedback. label Nov 22, 2023
@piether
Copy link
Author

piether commented Nov 22, 2023 via email

@yrodiere yrodiere removed the triage/needs-feedback We are waiting for feedback. label Nov 22, 2023
@beikov
Copy link
Contributor

beikov commented Nov 23, 2023

This is a bug that should be fixed as part of https://hibernate.atlassian.net/browse/HHH-17294 which will be part of 6.2.14.Final.
Using @Struct should work, but I'm curious, why does it not work for you @piether?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/hibernate-orm Hibernate ORM area/persistence OBSOLETE, DO NOT USE kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants