在 orm.xml (Spring Data / JPA 2.1 /Hibernate 5.3.7/Postgresql) 中定义@Type?

Define @Type in orm.xml (Spring Data / JPA 2.1 /Hibernate 5.3.7/Postgresql)?

我们需要对 Postgresql 中具有 jsonb 字段的对象执行 CRUD 操作。我知道我们可以创建一个用户类型并在模型中用 @Type(type = "jsonb") 注释它们。但是,我们想在 orm.xml 中定义元数据的映射而不是注释。我们也尝试过使用转换器,但仍然没有成功。是否有可能通过 orm.xml 实现这一目标?如何实现?谢谢

@Type 不是 JPA 规范的一部分。它是特定于 Hibernate 的。

JPA 注释的替代方法是 orm.xml。

Hibernate 注释的替代方法是 hbm.xml - hibernate 映射文件。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC 
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> 

<hibernate-mapping>
    <class name="" table="">
        <id></id>
        <property>
            <type name="">
            </type>
        </property>
    </class>
</hibernate-mapping>