Search code examples
springjaxbeclipselinkmoxy

Use of Multiple Inheritance in EclipseLink MOXy


I'm trying to use spring (@Autowire annotation into Jaxb Model class)

.....

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

@XmlTransient
@Autowired MediationCacheManager cacheManager;

Where MediationCacheManager is extended from three interfaces

On creation of JaxbContext i catch an exception: 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

Of course i understand that eclipselink doesn't support multiple inheritance but how can i skip cacheManager field from Jaxb processing? As for me - it should be done by XmlTransient annotation but its no work. Have u any idea?


Solution

  • The issue you are seeing corresponds to a bug (http://bugs.eclipse.org/411993) that we have fixed in the EclipseLink 2.5.1 and 2.6.0 streams. You can download a nightly build from the following link starting July 4, 2013:


    WORKAROUND

    You can use MOXy's external mapping document to override the supertype of MediationCacheManager to make your use case work (see: 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>
    

    Demo

    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);
        }
    
    }