【问题标题】:How to use custom converter org.eclipse.persistence.mappings.converters.Converter with EclipseList?如何将自定义转换器 org.eclipse.persistence.mappings.converters.Converter 与 EclipseList 一起使用?
【发布时间】:2013-06-17 18:15:29
【问题描述】:

我正在尝试实现 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 类中指定。TypeConverter 始终使用 @Convert 注释指定"

这是否意味着我们不能在 orm.xml 中提及转换?它的设计有什么原因吗(在 orm_2_1.XSD 中跳过了类型转换?)

【问题讨论】:

    标签: eclipselink converter


    【解决方案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>
    

    【讨论】:

      猜你喜欢
      • 2018-05-03
      • 2019-06-28
      • 2017-05-26
      • 2012-02-04
      • 2012-04-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-09
      相关资源
      最近更新 更多