Hi,

as far as I know, Castor currently ignores types when using references. It's not that this could not be changed/fixed, but in its current offering you have hit a stopper for you.

Let me know whether you'd like to investigate this a bit and have a look at the sources, as I'll be able to point you to the relevant source files.

Kind Regards
Werner Guttmann

On 18.02.2011 23:17, J Logan wrote:
Hi,

I'm running into an issue during unmarshalling using references, seemingly
because I have duplicate IDs across objects of different type.  Apologize in
advance if this is a FAQ; I searched the documentation and the web and didn't
see anything that points me in the right direction.

At first I was getting a "duplicate ID" error during unmarshalling, so I tried
setting org.exolab.castor.xml.lenient.id.validation to true.  This got me around

the duplicate ID checking, but then I see the exception:

Caused by: java.lang.IllegalArgumentException: Type conversion error: could not
set value

   of publisher(com.foo.catalog.Publisher) with value of type
com.foo.catalog.Title
        at
org.exolab.castor.mapping.loader.FieldHandlerImpl.setValue(FieldHandlerImpl.java:531)


        at
org.exolab.castor.xml.UnmarshalHandler.processIDREF(UnmarshalHandler.java:3316)
        at
org.exolab.castor.xml.UnmarshalHandler.processAttribute(UnmarshalHandler.java:3073)


        at
org.exolab.castor.xml.UnmarshalHandler.processAttributes(UnmarshalHandler.java:2777)


        at
org.exolab.castor.xml.UnmarshalHandler.startElement(UnmarshalHandler.java:2408)
        at
org.exolab.castor.xml.UnmarshalHandler.startElement(UnmarshalHandler.java:1436)

It seems that this occurs because there's both a publisher and a title whose
identity is 1.

Is there a way to qualify the IDs during marshalling so that this does not
occur?  The IDs on these objects are coming from the primary keys of the
database under the ORM I'm using.

Thanks in advance!

-- John Logan

MAPPING:

<?xml  version="1.0"?>

<!DOCTYPE mapping PUBLIC "-//EXOLAB/Castor Mapping DTD Version 1.0//EN"
"http://castor.org/mapping.dtd";;>

<mapping>
         <description>test mapping</description>

         <class name="com.foo.catalog.Publisher" identity="id"
auto-complete="true">
           <field name="id" type="long">
             <bind-xml name="publisherId" node="attribute"/>
           </field>
         </class>

         <class name="com.foo.catalog.Category" identity="id"
auto-complete="true">
           <field name="id"  type="long">
             <bind-xml name="categoryId" node="attribute"/>
           </field>
     </class>

     <class name="com.foo.catalog.Title" identity="id" auto-complete="true">
           <field name="id" type="long">
             <bind-xml name="titleId" node="attribute"/>
           </field>
           <field name="publisher" type="com.foo.catalog.Publisher">
             <bind-xml name="publisher" node="attribute" reference="true"/>
            </field>
           <field name="categories" type="com.foo.catalog.Category"
collection="collection">
             <bind-xml name="category" node="element" reference="true"/>
           </field>
     </class>
</mapping>

MARSHALLED XML SAMPLE:

<?xml version="1.0" encoding="UTF-8"?>
<catalog>
   <publisher publisherId="1">
     <name>A</name>
   </publisher>
   <publisher publisherId="2">
     <name>B</name>
   </publisher>
   <publisher publisherId="3">
     <name>C</name>
   </publisher>
   <publisher publisherId="4">
     <name>D</name>
    </publisher>
   <category categoryId="2016">
     <name>fashion</name>
   </category>
   <category categoryId="2017">
     <name>parenting</name>
   </category>
   <category categoryId="2018">
     <name>sports</name>
   </category>
   <title publisher="1" titleId="1">
     <category>2018</category>
     <category>2017</category>
     <category>2016</category>
     <name>E</name>
     <description>title description</description>
   </title>
   <title publisher="1" titleId="2">
     <category>2018</category>
      <category>2016</category>
     <name>F</name>
     <description>title description</description>
   </title>
   <title publisher="2" titleId="3">
     <category>2016</category>
     <name>G</name>
     <description>title description</description>
   </title>
   <title publisher="2" titleId="4">
     <category>2017</category>
     <name>H</name>
     <description>title description</description>
   </title>
   <title publisher="3" titleId="5">
     <category>2017</category>
     <name>I</name>
     <description>title description</description>
    </title>
   <title publisher="3" titleId="6">
     <category>2017</category>
     <name>J</name>
     <description>title description</description>
   </title>
   <title publisher="3" titleId="7">
     <category>2018</category>
     <name>K</name>
     <description>title description</description>
   </title>
   <title publisher="4" titleId="8">
     <name>L</name>
     <description>title description</description>
   </title>
</catalog>



____________________________________________________________________________________
Never miss an email again!
Yahoo! Toolbar alerts you the instant new Mail arrives.
http://tools.search.yahoo.com/toolbar/features/mail/

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

     http://xircles.codehaus.org/manage_email




---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email


Reply via email to