Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

SAXException2 with ID and IDREF

843834Aug 20 2007 — edited Jan 25 2008
Have 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.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 22 2008
Added on Aug 20 2007
4 comments
2,502 views