Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 327811

Summary: Problem with XmlElementRef and Inheritance
Product: z_Archived Reporter: Blaise Doughan <blaise.doughan>
Component: EclipselinkAssignee: Nobody - feel free to take it <nobody>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: eclipselink.oxm-inbox
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Example code demonstrating the problem
none
MOXy - Fix
none
MOXy - Test Cases
none
MOXy - Test Cases
none
MOXy - Fix
none
MOXy - Fix
none
MOXy - Test Cases
none
MOXy - Fix none

Description Blaise Doughan CLA 2010-10-14 14:07:37 EDT
Created attachment 180899 [details]
Example code demonstrating the problem

With the attached example the following exception is thrown:

Exception in thread "main" javax.xml.bind.JAXBException: 
Exception Description: Invalid XmlElementRef on property contactInfo on class blog.choice.Customer. Referenced Element not declared
 - with linked exception:
[Exception [EclipseLink-50006] (Eclipse Persistence Services - 2.1.0.v20100614-r7608): org.eclipse.persistence.exceptions.JAXBException
Exception Description: Invalid XmlElementRef on property contactInfo on class blog.choice.Customer. Referenced Element not declared]
	at org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(JAXBContextFactory.java:247)
	at org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(JAXBContextFactory.java:207)
	at org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(JAXBContextFactory.java:104)
	at org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(JAXBContextFactory.java:94)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:592)
	at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:201)
	at javax.xml.bind.ContextFinder.find(ContextFinder.java:330)
	at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:618)
	at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:565)
	at blog.choice.Demo.main(Demo.java:17)
Caused by: Exception [EclipseLink-50006] (Eclipse Persistence Services - 2.1.0.v20100614-r7608): org.eclipse.persistence.exceptions.JAXBException
Exception Description: Invalid XmlElementRef on property contactInfo on class blog.choice.Customer. Referenced Element not declared
	at org.eclipse.persistence.exceptions.JAXBException.invalidElementRef(JAXBException.java:133)
	at org.eclipse.persistence.jaxb.compiler.AnnotationsProcessor.processReferenceProperty(AnnotationsProcessor.java:1601)
	at org.eclipse.persistence.jaxb.compiler.AnnotationsProcessor.finalizeProperties(AnnotationsProcessor.java:602)
	at org.eclipse.persistence.jaxb.compiler.AnnotationsProcessor.processClassesAndProperties(AnnotationsProcessor.java:177)
	at org.eclipse.persistence.jaxb.compiler.Generator.<init>(Generator.java:143)
	at org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(JAXBContextFactory.java:244)
	... 12 more


Instead the following XML document should be produced:

<customer>
    <name>Jane Doe</name>
    <address>
        <city>Any Town</city>
        <street>1 A Street</street>
    </address>
</customer>
Comment 1 Blaise Doughan CLA 2010-10-15 11:33:04 EDT
Created attachment 180972 [details]
MOXy - Fix
Comment 2 Blaise Doughan CLA 2010-10-15 14:00:39 EDT
Created attachment 180997 [details]
MOXy - Test Cases
Comment 3 Blaise Doughan CLA 2010-10-15 14:04:15 EDT
Created attachment 180998 [details]
MOXy - Test Cases
Comment 4 Blaise Doughan CLA 2010-10-15 14:04:34 EDT
Created attachment 180999 [details]
MOXy - Fix
Comment 5 Blaise Doughan CLA 2010-10-25 16:44:13 EDT
Created attachment 181678 [details]
MOXy - Fix
Comment 6 Blaise Doughan CLA 2010-10-26 13:52:02 EDT
Created attachment 181751 [details]
MOXy - Test Cases
Comment 7 Blaise Doughan CLA 2010-10-26 13:53:53 EDT
Created attachment 181752 [details]
MOXy - Fix
Comment 8 Blaise Doughan CLA 2010-10-26 14:16:53 EDT
Fix checked into trunk at rev:  8412

Code reviewed by:  Matt MacIvor

Summary:
Instead of just checking for the element name corresponding to the property type, we now check for the element names of the property type and all subclasses.
Comment 9 Blaise Doughan CLA 2011-01-10 13:53:40 EST
Fixed as per above comments.
Comment 10 Eclipse Webmaster CLA 2022-06-09 10:17:03 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink
Comment 11 Eclipse Webmaster CLA 2022-06-09 10:24:11 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink