如何在EclipseList中使用自定义转换器org.eclipse.persistence.mappings.converters.Converter?

时间:2013-04-24 18:45:55

标签: eclipselink converter

我正在尝试实现org.eclipse.persistence.mappings.converters.Converter在我的orm.xml中使用它。大多数示例向我展示了如何使用注释来完成它。就像在实体类中使用@TypeConverter一样。但我不能使用注释。我如何尝试使用java创建orm.xml(基于使用xjc工具基于orm_2_1.xsd生成的java类)。由于某种原因,xsd定义中缺少类型转换器。

所以我的问题是如何在不使用注释的情况下使用自定义转换器。如何将它转到orm.xml?

This link说:

  

“...每个TypeConverter必须是唯一命名的,可以在类,字段和属性级别定义,并且可以在Entity,MappedSuperclass和Embeddable类中指定。始终使用@Convert注释指定TypeConverter”

这是否意味着我们不能在orm.xml中提及转换?它是否有任何设计原因(在orm_2_1.XSD中跳过了typeconvert?)

1 个答案:

答案 0 :(得分:1)

eclipselink docs

中描述了这一点

在eclipselink-orm.xml

<entity class="Employee"> 
... 
  <attributes> 
  ...
    <basic name="gender">
      <convert>genderConverter</convert>
      <converter name="genderConverter" class="org.myorg.converters.GenderConverter"/>
    </basic> 
  ... 
  </attributes> 
</entity>