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

标签 java hibernate jpa

我有一个包含 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/

相关文章:

java - 在 Eclipse 中启动 Tomcat 时出错

java - Jboss EAP 7.0+Hibernate 5+Azure DB : DataSource returns SQL Error: 0, SQLState:空

java - 为什么 ORDER BY DATEDIFF 在使用 JPA 的 SQL 服务器上引发异常?

java - 具有连接实体属性的 Micronaut Data DTO 投影

java - 无法删除或更新父行 : a foreign key constraint fails and Entity hierarchy mustn't change

java - 不活动 transaciotn : javax. persistence.TransactionRequiredException:执行更新/删除查询

java - 创建 Windows XP 联结

hibernate - 在 Glassfish 服务器上配置 Hibernate JPA 2.0 的学习资源

java - 使用 JPA/JTA/JBOSS/CDI 不会持久化对象

java - JSONMappingException - 无法反序列化 Java 对象