Search code examples
hibernategrailsgrails-ormjsonb

How to integrate JSON into Grails 4 (Gorm 7, Hibernate 5.4)?


Grails 4.0.10, GORM 7.0.8 RELEASE, Hibernate 5.4, Postgresql 11

I have a "data" jsonb column in Postgres. I have been trying to map that up through Hibernate/GORM. To build.gradle I have added

  compile 'com.vladmihalcea:hibernate-types-52:2.17.3'

My Grails entity property has:

data type: 'jsonb', sqlType: 'jsonb'

At the moment I get a null property exception from
com.vladmihalcea.hibernate.type.json.internal.JsonTypeDescriptor:

    public Object fromString(String string) {
        if (String.class.isAssignableFrom(propertyClass)) {
            return string;
        }
        return objectMapperWrapper.fromString(string, propertyType);
    }

In this case propertyClass and propertyType are both null. In other words, the type declaration of the property is not mapped so that the JsonTypeDescriptor class sees it. I have tried various hibernate annotations with @TypeDef and @Type. The Grails documentation has this brief note on the column "type" descriptor:
"Hibernate also has the concept of custom UserType implementations. In this case you specify the UserType class."

No combination of declarations has worked for me; through all of this I cannot write a JSON string into the jsonb database column. What is the correct solution?


Solution

  • You should be using this, where the work was already done:

    https://github.com/kaleidos/grails-postgresql-extensions