gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 13:10:46 25 4
gpt4 key购买 nike

我们需要对 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>

关于postgresql - 在orm.xml(Spring Data/JPA 2.1/Hibernate 5.3.7/Postgresql)中定义@Type?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55046340/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com