无法实例化 JsonBinaryType 的 AttributeConverter

问题描述 投票:0回答:1

我最近将 springboot 版本升级到了 3.0.2。此外,hibernate 依赖项已升级到 6.1.6.Final。 我正在使用 hypersistence util 中的 hibernate-type 60。

<dependency>
      <groupId>org.hibernate.orm</groupId>
      <artifactId>hibernate-core</artifactId>
      <scope>compile</scope>
      <version>6.1.6.Final</version>
    </dependency>
    
    <dependency>
        <groupId>io.hypersistence</groupId>
        <artifactId>hypersistence-utils-hibernate-60</artifactId>
        <version>3.2.0</version>
    </dependency>

升级后,我无法在 JsonBinaryType 列上创建 bean。我使用此列将 json 对象作为 jsonb 结构存储在我的 postgresql 数据库中。 但是,我收到以下异常:

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]: Unable to instantiate AttributeConverter [io.hypersistence.utils.hibernate.type.json.JsonBinaryType]
Caused by: java.lang.IllegalStateException: Unable to instantiate AttributeConverter [io.hypersistence.utils.hibernate.type.json.JsonBinaryType]
Caused by: org.hibernate.AnnotationException: Unable to create AttributeConverter instance
Caused by: org.hibernate.AnnotationException: Could not extract type argument from attribute converter class 'io.hypersistence.utils.hibernate.type.json.JsonBinaryType'

具有 hibernate-type-52 依赖项的代码

@Entity
@Table(name = "test_table")
@TypeDef(name = "jsonb", typeClass = JsonBinaryType.class)
public class TestTable implements Serializable {

  private static final long serialVersionUID = 1L;

  @Type(type = "jsonb")
  @Column(name = "payload_data", columnDefinition = "jsonb")
  private Object payload;
}

升级到hypersistence-utils-hibernate-60依赖后的代码

 @Entity
    @Table(name = "test_table")
    public class TestTable implements Serializable {
    
      private static final long serialVersionUID = 1L;
    
      @Convert(converter = JsonBinaryType.class)
      @Column(name = "payload", columnDefinition = "jsonb")
      private Object payload;
    }

我在这里缺少什么。我该如何解决这个问题,需要帮助。

-谢谢 斯里坎特·曼萨

spring-boot hibernate spring-data-jpa hibernate-types
1个回答
0
投票

非常好

@Type(JsonBinaryType.class)
@Column(columnDefinition = "jsonb")
© www.soinside.com 2019 - 2024. All rights reserved.