Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 327811 - Problem with XmlElementRef and Inheritance
Summary: Problem with XmlElementRef and Inheritance
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: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-10-14 14:07 EDT by Blaise Doughan CLA
Modified: 2022-06-09 10:24 EDT (History)
1 user (show)

See Also:


Attachments
Example code demonstrating the problem (1.99 KB, application/octet-stream)
2010-10-14 14:07 EDT, Blaise Doughan CLA
no flags Details
MOXy - Fix (1.87 KB, patch)
2010-10-15 11:33 EDT, Blaise Doughan CLA
no flags Details | Diff
MOXy - Test Cases (16.68 KB, patch)
2010-10-15 14:00 EDT, Blaise Doughan CLA
no flags Details | Diff
MOXy - Test Cases (17.24 KB, patch)
2010-10-15 14:04 EDT, Blaise Doughan CLA
no flags Details | Diff
MOXy - Fix (1.88 KB, patch)
2010-10-15 14:04 EDT, Blaise Doughan CLA
no flags Details | Diff
MOXy - Fix (2.19 KB, patch)
2010-10-25 16:44 EDT, Blaise Doughan CLA
no flags Details | Diff
MOXy - Test Cases (18.30 KB, patch)
2010-10-26 13:52 EDT, Blaise Doughan CLA
no flags Details | Diff
MOXy - Fix (3.29 KB, patch)
2010-10-26 13:53 EDT, Blaise Doughan 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 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