Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 353787 - Exception thrown for subclass when @XmlID is on parent class
Summary: Exception thrown for subclass when @XmlID is on parent class
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Denise Smith CLA
QA Contact:
URL: http://stackoverflow.com/questions/69...
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-08-03 11:32 EDT by Blaise Doughan CLA
Modified: 2022-06-09 10:09 EDT (History)
1 user (show)

See Also:


Attachments
Proposed changes and tests (17.34 KB, patch)
2011-08-03 14:26 EDT, Denise Smith CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Blaise Doughan CLA 2011-08-03 11:32:05 EDT
Given the following object model:

    package forum6928521;

    import java.util.Random;

    import javax.xml.bind.annotation.XmlAttribute;
    import javax.xml.bind.annotation.XmlID;

    public class Small {
        private String xmlId;

        @XmlID
        @XmlAttribute
        public String getXmlId() {
            if (xmlId == null)
                xmlId = "small" + new Random().nextInt();
            return xmlId;
        }

        public void setXmlId(String id) {
            this.xmlId = id;
        }
    }

and

    package forum6928521;

    public class Big extends Small {
        // Code
    }

The following exception is incorrectly being thrown since the Big class should inherit the @XmlID from the parent class:

Exception Description: Invalid XmlIDREF on property [big].  Class [forum6928521.Big] is required to have a property annotated with XmlID.]
	at org.eclipse.persistence.jaxb.JAXBContext$TypeMappingInfoInput.createContextState(JAXBContext.java:825)
	at org.eclipse.persistence.jaxb.JAXBContext.<init>(JAXBContext.java:136)
	at org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(JAXBContextFactory.java:142)
	at org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(JAXBContextFactory.java:129)
	at org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(JAXBContextFactory.java:93)
	at org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(JAXBContextFactory.java:83)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at javax.xml.bind.ContextFinder.newInstance(Unknown Source)
	at javax.xml.bind.ContextFinder.find(Unknown Source)
	at javax.xml.bind.JAXBContext.newInstance(Unknown Source)
	at javax.xml.bind.JAXBContext.newInstance(Unknown Source)
	at forum6928521.Test2.main(Test2.java:25)
Caused by: Exception [EclipseLink-50017] (Eclipse Persistence Services - 2.3.1.qualifier): org.eclipse.persistence.exceptions.JAXBException
Exception Description: Invalid XmlIDREF on property [big].  Class [forum6928521.Big] is required to have a property annotated with XmlID.
	at org.eclipse.persistence.exceptions.JAXBException.invalidIdRef(JAXBException.java:184)
	at org.eclipse.persistence.jaxb.compiler.AnnotationsProcessor.finalizeProperties(AnnotationsProcessor.java:769)
	at org.eclipse.persistence.jaxb.compiler.AnnotationsProcessor.processClassesAndProperties(AnnotationsProcessor.java:236)
	at org.eclipse.persistence.jaxb.compiler.Generator.<init>(Generator.java:147)
	at org.eclipse.persistence.jaxb.JAXBContext$TypeMappingInfoInput.createContextState(JAXBContext.java:822)
	... 14 more
Comment 1 Denise Smith CLA 2011-08-03 14:26:49 EDT
Created attachment 200843 [details]
Proposed changes and tests
Comment 2 Denise Smith CLA 2011-08-03 14:55:36 EDT
Fixed in trunk (2.4) and 2.3.1

Changed annotationsprocessor so subtypes know about there parent`s XML ID Property if one is set.
Comment 3 Denise Smith CLA 2011-08-03 15:07:40 EDT
Added new test in jaxb.xmlidref
Comment 4 Eclipse Webmaster CLA 2022-06-09 10:09:24 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink