vladmihalcea/hypersistence-utils

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.boot.registry.classloading.spi.ClassLoadingException: Unable to load class [com.vladmihalcea.hibernate.type.json.JsonBinaryType]

vinodhvp opened this issue · 1 comments

I have an existing project which builds , runs and deploys well.
But when I add jsonb/JsonBinaryType into my entity class, it starts throwing errors during build.
The error is thrown while running junit test cases.

  1. My Entity class:
    import com.vladmihalcea.hibernate.type.json.JsonBinaryType;
    @typedef(name = "jsonb", typeClass = JsonBinaryType.class)
    public class MyEntity implements Serializable {
    @column(name = "payload", columnDefinition = "jsonb")
    @type(type = "jsonb")
    private String payload;
    }

  2. My dialect class:
    import org.hibernate.dialect.PostgreSQL94Dialect;
    public class JsonPostgreSQL94Dialect extends PostgreSQL94Dialect {
    public JsonPostgreSQL94Dialect() {
    this.registerColumnType(Types.JAVA_OBJECT, "jsonb");
    }
    }

  3. My maven dependencies:
    com.h2database:h2:jar:1.4.194:test
    com.vladmihalcea:hibernate-types-52:jar:2.9.3:compile
    org.hibernate:hibernate-core:jar:5.4.11.Final:compile
    org.springframework.boot:spring-boot-starter-data-jpa:jar:2.5.15:compile
    org.jacoco:org.jacoco.agent:jar:runtime:0.8.11:test
    org.springframework.boot:spring-boot-starter-test:jar:2.5.15:test

  4. My property class entry:
    spring.jpa.properties.hibernate.dialect=com.******.JsonPostgreSQL94Dialect #My custom class
    spring.jpa.database-platform=org.hibernate.dialect.PostgreSQL9Dialect

As explained in the README file, the Hibernate Types project was migrated to Hypersistence Utils. However, support for the 52 module was dropped and will no longer be maintained.

In your case, the problem is most likely caused by the ClassLoader. Make sure the dependency is available at runtime as well, not only at compile time.