SAXException2 with ID and IDREF
843834Aug 20 2007 — edited Jan 25 2008Have an XSD that declares an object with an ID and another object with an IDREF as follows:
<xs:element name="subject" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="id" type="xs:ID" use="required"/>
<xs:attribute name="name" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="subjectRelationship" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="parentSubject" type="xs:IDREF" use="required"/>
<xs:attribute name="childSubject" type="xs:IDREF" use="required"/>
</xs:complexType>
</xs:element>
Using JAXB, I instantiate and add two "subject" objects. The first has attribute id of "z1_id" and attribute name of "z1_name". The second has attribute id of "z2_id" and attribute name of "z2_name".
Again using JAXB, I instantiate and add one "subjectRelationship" object. It has attribute parentSubject of "z1_id" and attribute childSubject of "z2_id".
When I attempt to marshal the above, I get the following exception:
com.sun.istack.SAXException2: Object "z1_id" is found in an IDREF property but this object doesnt have an ID.
I presume that I am guilty of some misunderstanding of the ID and IDREF mechanism, but what? I cannot find any example on the web of a proper ID and IDREF implementation. Thanks.