Quarkus: JPA AttributeConverter does not persist entity in some cases

Created on 11 Nov 2020  路  6Comments  路  Source: quarkusio/quarkus

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)

arehibernate-orm arepersistence kinbug

All 6 comments

/cc @Sanne, @gsmet

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.

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

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.

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

@Sanne @beikov Thanks!

Was this page helpful?
0 / 5 - 0 ratings