如何在JPA XML映射文件中使用AttributeConverter(JPA 2.1)? [英] How to use AttributeConverter(JPA 2.1) in JPA XML mapping file?
问题描述
我有一个包含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屋!