如何在JPA XML映射文件中使用AttributeConverter(JPA 2.1)? [英] How to use AttributeConverter(JPA 2.1) in JPA XML mapping file?

查看:134
本文介绍了如何在JPA XML映射文件中使用AttributeConverter(JPA 2.1)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a class that contains a XMLGregorianCalendar property, which is not a basic type supported by hibernate. The User Guide tells me an AttributeConverter is a solution. However I found it has to be implemented with annotation @Converter and I got this:

我需要处理的属性是:

因此,我尝试使用休眠映射文件,但是在其中找不到任何转换器标签.我该如何解决这个问题?

So I try to use hibernate mapping file, but I find no converter tags in it. How could I solve this problem?

推荐答案

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

you can add it to your entity mapping as described in this tutorial (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>

这篇关于如何在JPA XML映射文件中使用AttributeConverter(JPA 2.1)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆