gpt4 book ai didi

java - 如何在 JPA XML 映射文件中使用 AttributeConverter(JPA 2.1)?

转载 作者:行者123 更新时间:2023-12-01 21:45:09 26 4
gpt4 key购买 nike

我有一个包含 XMLGregorianCalendar 属性的类,该属性不是 hibernate 支持的基本类型。用户指南告诉我 AttributeConverter 是一个解决方案。但是我发现它必须使用注释 @Converter 来实现,我得到了这个:

enter image description here

我需要处理的属性是:

enter image description here

所以我尝试使用 hibernate 映射文件,但我发现其中没有转换器标签。我该如何解决这个问题?

最佳答案

您可以按照本教程 ( http://www.thoughts-on-java.org/how-to-use-jpa-type-converter-to/ ) 中的说明将其添加到实体映射中

<entity-mappings version="2.1"
xmlns="http://xmlns.jcp.org/xml/ns/persistence/orm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence/orm_2_1.xsd">

<entity class="x.y.Entity">
<convert converter="x.y.CryptoConverter" attribute-name="yourField"/>
</entity>
</entity-mappings>

关于java - 如何在 JPA XML 映射文件中使用 AttributeConverter(JPA 2.1)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36075467/

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