简体   繁体   中英

How to use AttributeConverter(JPA 2.1) in JPA XML mapping file?

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:

在此处输入图片说明

The property I need to handle is:

在此处输入图片说明

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

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM