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

JPA AttributeConverter does not persist entity in some cases #13234

Closed
mposolda opened this issue Nov 11, 2020 · 6 comments · Fixed by #13352
Closed

JPA AttributeConverter does not persist entity in some cases #13234

mposolda opened this issue Nov 11, 2020 · 6 comments · Fixed by #13352
Labels
area/hibernate-orm Hibernate ORM area/persistence OBSOLETE, DO NOT USE kind/bug Something isn't working
Milestone

Comments

@mposolda
Copy link

Describe the bug
In Keycloak, we use the AttributeConverter implementation. The use-case is to save the JSON String into one column in the database table. Hence we use the converter, which converts the Map object into JSON String and this JSON String is then supposed to be saved in the DB in the column of type CLOB.

The code of the converter is here: https://github.com/mposolda/keycloak/blob/KEYCLOAK-16244-quarkus-reproduce/model/jpa/src/main/java/org/keycloak/models/jpa/converter/MapStringConverter.java

It is used in the entity as shown here: https://github.com/mposolda/keycloak/blob/KEYCLOAK-16244-quarkus-reproduce/model/jpa/src/main/java/org/keycloak/models/jpa/entities/RealmLocalizationTextsEntity.java#L79 (The TEXTS column is supposed to be just String (CLOB) in the database.)

The issue is when we update the map and update the value for some key in the map as shown here:
https://github.com/mposolda/keycloak/blob/KEYCLOAK-16244-quarkus-reproduce/model/jpa/src/main/java/org/keycloak/models/jpa/JpaRealmProvider.java#L894

then the entity is not updated in the DB. When adding completely new "key" or removing the key from the map, the object is correctly updated in the DB. The issue is just updating the value of existing key in the map. Which means that "map" has exactly same keys as before, however it just has different values. In case that keys in the map were changed (adding or removing key to the map), things work as expected.

I am not 100% sure if this is bug in the quarkus hibernate subsystem, but the behaviour on "standalone" hibernate or when using on Wildfly is working fine. So I assume it is Quarkus bug, but not 100%...

Let me know if this is enough description, or if you want me to provide some more proper reproducer.

Quarkus version: 1.9.1.Final

java -version:
openjdk version "11.0.9" 2020-10-20
OpenJDK Runtime Environment (build 11.0.9+11-Ubuntu-0ubuntu1.18.04.1)
OpenJDK 64-Bit Server VM (build 11.0.9+11-Ubuntu-0ubuntu1.18.04.1, mixed mode, sharing)

@mposolda mposolda added the kind/bug Something isn't working label Nov 11, 2020
@ghost ghost added area/hibernate-orm Hibernate ORM area/persistence OBSOLETE, DO NOT USE labels Nov 11, 2020
@ghost
Copy link

ghost commented Nov 11, 2020

/cc @Sanne, @gsmet

@Sanne
Copy link
Member

Sanne commented Nov 11, 2020

hi @mposolda , I suspect this triggers some unexpected interaction with the entity enhancement, which we use in Quarkus (and didn't use in WildFly).

The problem would be that technically you're not writing onto the property. Would you be able to verify this theory, by using a workaround which makes the property write explicit?

Map texts = entity.getTexts();
texts.put(key, text);
entity.setTexts( texts ); /// explicit setter being invoked

I'm not entirely sure of this, as I don't know why it would seem to work when you change keys.

@mposolda
Copy link
Author

@Sanne Thanks, I've tried this but there was not any change in the behaviour. Explicitly calling "setter" does not help...

@Sanne
Copy link
Member

Sanne commented Nov 13, 2020

Interesting, thanks for trying @mposolda . I'll see if someone on the team can prioritize this, but TBH it won't be looked at before next week.

@beikov
Copy link
Contributor

beikov commented Nov 13, 2020

I created https://hibernate.atlassian.net/browse/HHH-14329 to track this, as this is indeed an enhancement issue.

@mposolda
Copy link
Author

@Sanne @beikov Thanks!

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.

4 participants