Skip to main content

SAXException2 with ID and IDREF

4 replies [Last post]
Joined: 2007-04-13

Have an XSD that declares an object with an ID and another object with an IDREF as follows:

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.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2008-01-07

same error for me...

Joined: 2007-04-13

The solution was to instantiate and set into the IDREF object the same kind of object that contains the ID. Then the marshaller can make the IDREF to ID references.

Using the XSD in my first post above, I first create two "subject" objects, one with an "id" attribute of "z1_id", another with an "id" attribute of "z2_id".

Then I create one "subjectRelationship" object [with the IDREF].

I now create yet a third "subject" object, with an "id" attribute of "z1_id". I then use JAXB method "setParentSubject" to place this third "subject" object into the "subjectRelationship" object. And I then create yet a fourth "subject" object, with an "id" attribute of "z2_id". I then use JAXB method "setChildSubject" to place this fourth "subject" object into the "subjectRelationship" object.

That works. The marshaller is happy.

You can try creating a fifth "subject" object, with an "id" attribute of "z3_id", inserting that into the "subjectRelationship", and see the IDREF linkage fail.

If the above is not clear, I can post the actual Java code.

Joined: 2008-07-15

Hi Frank,

I have the same problem...
Please post the code so that i can understan it better

Joined: 2007-06-18


I am facing the same problem. Have you found any solution for that?

Thanks in advance!