首页 > 解决方案 > JPA+JSONB 集合上的休眠方案验证失败

问题描述

我正在尝试将 JSONB 列映射到 Set(非内置目标),但是当方案验证器在开始时运行时,它会失败,因为我没有连接表(此模型不需要)。

@Entity
@Table(name = "my_class")
public classs Class extends BaseEntity<Long> {

    @ElementCollection(targetClass = ClassSchedule.class) // This is to correctly map the generated meta-model
    @Column(name = "schedules", nullable = false, columnDefinition = "JSONB")
    @Convert(attributeName = "schedules", converter = ClassSchedule.ClassSchedulesConverter.class) //Class's mapper
    private Set<ClassSchedule> schedules;

}

由于添加了@ElementCollection注释,当我运行此代码时,hibernate 仍希望此表class_schedule存在。我知道我可以从配置中禁用方案验证,但我宁愿避免这样做。

关于如何正确映射该字段的任何想法?

编辑:

虽然我可以使用@Typehybernate 的类型(我最初是这样做的),但它会导致元模型生成/映射出现问题:

expected type :  org.hibernate.metamodel.model.domain.internal.SingularAttributeImpl; encountered type : javax.persistence.metamodel.SetAttribute

这就是为什么我决定添加@ElementCollection现在提示当前问题的原因,因为它需要一个连接表。

标签: javaspringhibernatejpa

解决方案


推荐阅读