Title: element XXX occurs more than once

Hello,

Prior to updating to Castor 1.0 I was encountering several issues with deriveByClass elements nested in location elements.  There was a fix in version 1.0 that eliminated those particular errors, but now I am encountering "element XXX occurs more than once" errors.  I have made several comments in the Bugzilla issue tracker (Bugzilla ID 1550, http://jira.codehaus.org/browse/CASTOR-690).  The basics are:

- The problem appears in version 1.0 (original ticket lists version 0.9.5.3 as well)
- It appears when deriveByClass and location are used together
- Replacing deriveByClass with a static name works around the issue, but raises other issues with inheritance
- Removing the location causes the error to go away, but confuses the unmarshaller (does not know where collections begin or end without the wrapper element)

- In my situation, I am using the same element in two different places (parent elements) with deriveByName and the same location.  Implementing either of the above work-arounds in either lace makes the error go away.  Renaming the location in either place also works around the problem.

Now, after renaming one of the location elements, I experience some quirky behavior in the unmarshaller.  For example, my schema is roughly equivalent to this:

<class name="Account">
   <map-to xml="acct"/>
   <!-- Some fields -->
   <field name="customer" type="Party">
      <bind-xml auto-naming="deriveByClass" node="element" location="cust"/>
   </field>
   <!-- some other fields -->
   <field name="contacts" type="Contact" collection="set">
      <bind-xml auto-naming="deriveByClass" node="element" location="contacts"/>
      <!-- Contact extends Party -->
   </field>
   <!-- More fields -->
</class>

In my test I did not specify a customer, so I got the following XML:

<acct>
   <contacts><!-- location wrapper -->
      <contact id="1" ...> ... </contact>
      <contact id="2" ...> ... </contact>
      ...
   </contacts>
</acct>

But when I unmarshalled the same XML and re-marshalled it, I got this:

<acct>
    ...
    <cust><!-- location wrapper -->
        <contact id="1" ...> ... </contact>
    </cust>
    ...
    <contacts><!-- location wrapper -->
        <contact id="2" ...> ... </contact>
        ...
    </contacts>
    ...
</acct>

For some reason the unmarshaller identified the first <contact> element in the <contacts> wrapper to be the customer (<cust>).  Since there can be only one customer, might this be why the "element contact appears more than once" error happens?  i.e. the unmarshaller does not correctly identify the element mapping when locations are used?  It almost seems like it ignores the location . . .

Any insight would be greatly appreciated.

Thanks,

- Jesse

Reply via email to