I am trying to get JSONB type working with liquibase-hibernate5 extension, but without any luck. I am using liquibase core and the extension version 4.10. I am using liquibase within Spring boot 2.5.14. I have added my own dialect file of Postgres to add support for JSONB:
public class PostgreSQLDialect extends PostgreSQL10Dialect {
public PostgreSQLDialect() {
// Support for JsonB, else the liquibase mvn plugin will fail.
// Ref: https://thorben-janssen.com/persist-postgresqls-jsonb-data-type-hibernate/
System.out.println("Registering the JSONB type.");
this.registerColumnType(Types.JAVA_OBJECT, "jsonb");
}
}
And registered it in the application.yml file:
spring.jpa.properties.hibernate.dialect: my.example.PostgreSQLDialect
And also added it to the liquibase ref URL in the pom.xml
<referenceUrl>hibernate:spring:my.example.persist?dialect=my.exampple.PostgreSQLDialect&hibernate.physical_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy&hibernate.implicit_naming_strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyComponentPathImpl</referenceUrl>
But still when running the mvn liquibase:diff command it shows in the output it's using the Dialect class, and also registers the jsonb file, but keeps complaining that it can't load the class:
Caused by: java.lang.ClassNotFoundException: Could not load requested class : jsonb
Anybody any idea? I bounced my head a few times against this, and always worked around it by temp commenting the jsonb usages in the code, but would really love to solve this.
More about the stacktrace:
Caused by: java.lang.ClassNotFoundException: Could not load requested class : jsonb
at org.hibernate.boot.registry.classloading.internal.AggregatedClassLoader.findClass (AggregatedClassLoader.java:210)
at java.lang.ClassLoader.loadClass (ClassLoader.java:589)
at java.lang.ClassLoader.loadClass (ClassLoader.java:522)
at java.lang.Class.forName0 (Native Method)
at java.lang.Class.forName (Class.java:427)
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.classForName (ClassLoaderServiceImpl.java:130)
at org.hibernate.boot.internal.ClassLoaderAccessImpl.classForName (ClassLoaderAccessImpl.java:67)
at org.hibernate.cfg.annotations.SimpleValueBinder.fillSimpleValue (SimpleValueBinder.java:536)
at org.hibernate.cfg.SetSimpleValueTypeSecondPass.doSecondPass (SetSimpleValueTypeSecondPass.java:25)
at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processSecondPasses (InFlightMetadataCollectorImpl.java:1693)
at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processSecondPasses (InFlightMetadataCollectorImpl.java:1651)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete (MetadataBuildingProcess.java:295)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata (EntityManagerFactoryBuilderImpl.java:1224)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build (EntityManagerFactoryBuilderImpl.java:1255)
at liquibase.ext.hibernate.database.HibernateEjb3Database.buildMetadataFromPath (HibernateEjb3Database.java:59)
at liquibase.ext.hibernate.database.HibernateDatabase.buildMetadata (HibernateDatabase.java:143)
at liquibase.ext.hibernate.database.HibernateDatabase.setConnection (HibernateDatabase.java:83)
.....