Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] [MOXy] mapping inheritance of schema types


My schema defines the following inheritance:  

	<xsd:complexType name="RootType" abstract="true">
			<xsd:element ref="field1" minOccurs="0"/>

	<xsd:complexType name="BranchType" abstract="true">
			<xsd:extension base="RootType">
					<xsd:element ref="field2" maxOccurs="unbounded"/>

	<xsd:complexType name="LeafType">
			<xsd:extension base="BranchType">
					<xsd:element ref="field3" maxOccurs="unbounded"/>

The Java classes also mirror this inheritance tree:

public class Root {
    private String field1;

public class Branch extends Root {
    private String field2;

public class Leaf extends Branch {
    private String field3;

Actually, Root and Branch ought to be abstract classes, but EclipseLink
threw instantiation exceptions complaining about missing no-arg constructor
until I took out the "abstract".

I expect to parse XML that looks like this into the Leaf object:


I don't want to redundantly map the fields from Branch and Root in Leaf, so
I am trying to map each of those classes to its corresponding type in the
schema.  In the Workbench, I have these settings:

1.  Leaf has a mapping for field3, the class is marked as a child
descriptor, and its parent is Branch.  
2.  Branch has a mapping for field2, the class is marked as a child
descriptor, and its parent is Root.  
3.  Root has a mapping for field1, the class is marked as a parent, and
then... I'm stuck.

The problem is:
* I cannot use the Class Extraction Method, because it looks like this hook
is never called for XML projects.

* I cannot use the Class Indicator Field's "xml schema type attribute",
because I assume this means that I need an an attribute like
"xsi:type='Leaf'", and my schema does not allow this attribute.

* I cannot use the Class Indicator Field's "specify field" setting because
there's no element inside the <Leaf></Leaf> tags that will tell me what
class to use.  

So I am perplexed.  How come EclipseLink can't tell that it should use the
Leaf class if the xml element name is "Leaf"?  I have already set the
"Schema Context" to "Leaf".  Why does EclipseLink need something else to
tell it what type to use?  

Is there a better way to specify inheritance in XML mappings without having
to use the Map Inherited Attributes -> To Root Minus One option?  That would
force me to remap the same attributes over and over again and be a pain if
the root definition ever changes.  

Thanks for your help,
View this message in context:
Sent from the EclipseLink - Users mailing list archive at

Back to the top