【问题标题】:Use of Multiple Inheritance in EclipseLink MOXy在 EclipseLink MOXy 中使用多重继承
【发布时间】:2013-07-03 21:59:59
【问题描述】:

我正在尝试使用 spring(@Autowire 注释到 Jaxb 模型类中)

.....

@XmlAttribute(name = "object-id")
@XmlSchemaType(name = "positiveInteger")
protected BigInteger objectId;

@XmlTransient
@Autowired MediationCacheManager cacheManager;

MediationCacheManager 是从三个接口扩展而来的

在创建 JaxbContext 时,我捕获了一个异常: Exception [EclipseLink-50089] (Eclipse Persistence Services - 2.5.0.v20121116-8650760): org.eclipse.persistence.exceptions.JAXBException Exception Description: The java interface com.netcracker.mediation.common.caches.api.MediationCacheManager can not be mapped by JAXB as it has multiple mappable parent interfaces. Multiple inheritence is not supported

当然我知道 eclipselink 不支持多重继承,但我如何从 Jaxb 处理中跳过 cacheManager 字段?至于我 - 它应该通过 XmlTransient 注释来完成,但它不起作用。你有什么想法吗?

【问题讨论】:

标签: spring jaxb eclipselink moxy


【解决方案1】:

您看到的问题对应于我们在 EclipseLink 2.5.1 和 2.6.0 流中修复的错误 (http://bugs.eclipse.org/411993)。从 2013 年 7 月 4 日起,您可以从以下链接下载每晚构建:


解决方法

您可以使用 MOXy 的外部映射文档覆盖 MediationCacheManager 的超类型以使您的用例工作(请参阅:http://blog.bdoughan.com/2010/12/extending-jaxb-representing-annotations.html):

oxm.xml

<?xml version="1.0"?>
<xml-bindings
    xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm"
    package-name="forum17458822">
    <java-types>
        <java-type name="MediationCacheManager" super-type="java.lang.Object"/>
    </java-types>
</xml-bindings>

演示

import java.util.*;
import javax.xml.bind.JAXBContext;
import org.eclipse.persistence.jaxb.JAXBContextProperties;

public class Demo {

    public static void main(String[] args) throws Exception {
        Map<String, Object> properties = new HashMap<String, Object>(1);
        properties.put(JAXBContextProperties.OXM_METADATA_SOURCE, "forum17458822/oxm.xml");
        JAXBContext jc = JAXBContext.newInstance(new Class[] {Foo.class}, properties);
    }

}

【讨论】:

    猜你喜欢
    • 2012-02-15
    • 2014-12-23
    • 1970-01-01
    • 2012-06-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-11
    相关资源
    最近更新 更多