如何使用JPA / Hibernate映射XMLType [英] How to map XMLType with JPA/Hibernate
问题描述
如何通过JPA / Hibernate持久化XMLType列?根据oracle文档,在声明XMLType的存储子句时有两种方法。它们是LOB和对象关系。我不想和LOB一起去。我有架构并注册到数据库中。我没有关于如何设计我的XMLType实体的例子。是否有人知道请分享它?
这对我来说很好(JPA 2.1和Hibernate 5.1.0):
- 在实体中以字符串形式创建字段。
- 使用Hibernate中的@ColumnTransformer注释来定义如何读取和写入列。
-
将@Column中的columnDefinition设置为XMLType
@ ColumnTransformer(read =to_clob(columnName),write =?)
@Column(name =COLUMN_NAME,columnDefinition =XMLType)
$ b $ private String columnName;
How to persist XMLType column via JPA/Hibernate? As per oracle documentation, there are two ways in declaring storage clause for XMLType. They are, LOB and Object-Relational. I dont want to go with LOB. I have schema and register into database. I have not have example on how to design my Entity for XMLType. Does any one know please share it?
This is working fine for me (JPA 2.1 and Hibernate 5.1.0):
- Create the field in the entity as a String.
- Use the @ColumnTransformer annotation from Hibernate to define how to read and write from the column.
Set the columnDefinition in @Column as "XMLType"
@ColumnTransformer(read = "to_clob(columnName)", write = "?")
@Column(name = "COLUMN_NAME", columnDefinition = "XMLType")
private String columnName;
这篇关于如何使用JPA / Hibernate映射XMLType的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!