Hi all,
I'm using jibx 1.1.5 with hibernate classes. These classes have been generated
by Hibernate Synchronizer tool from our database schema. java.util.Set<> are
used to represent one-to-many relations, which are collections in the binding
file. When I try to marshall a collection (with my own marshaller), I got a
ClassCastException java.lang.String (And I'm not entered in my marshaller yet )
The same marshaller is used for structure and works fine. Unmarshaller works
fine too. Can anyone please help me ? (I tried to use a Set factory and got
the same error)
-------error--------------
Exception in thread "main" java.lang.ClassCastException: java.lang.String
at
ca.gc.nrcan.mis_nap.data.JiBX_MungeAdapter.JiBX_jibx_genbinding_binding_marshal_1_0()
at
ca.gc.nrcan.mis_nap.data.base.BaseMdMetadata.JiBX_jibx_genbinding_binding_marshal_1_2(BaseMdMetadata.java)
at
ca.gc.nrcan.mis_nap.data.MdMetadata.JiBX_jibx_genbinding_binding_marshal_2_2(MdMetadata.java)
at
ca.gc.nrcan.mis_nap.data.JiBX_jibx_genbinding_bindingMdMetadata_access1.marshal()
at ca.gc.nrcan.mis_nap.data.MdMetadata.marshal(MdMetadata.java)
at
org.jibx.runtime.impl.MarshallingContext.marshalRoot(MarshallingContext.java:1044)
at
org.jibx.runtime.impl.MarshallingContext.marshalDocument(MarshallingContext.java:1114)
at LireXML.main(LireXML.java:40)
---------classes--------
public class MdMetadata extends BaseMdMetadata {
[...]
}
public abstract class BaseMdMetadata implements Serializable {
// primary key
private java.lang.Long id;
// fields
private java.lang.String fileidentifier;
private java.lang.String language;
// collections
private java.util.Set<ca.gc.nrcan.mis_nap.data.Hierarchylevelname>
objHierarchylevelnameSet;
[...]
}
----------binding----------------------
<binding forwards="false" value-style="attribute">
<mapping class="ca.gc.nrcan.mis_nap.data.MdMetadata" name="MD_Metadata">
<namespace uri="http://www.isotc211.org/2005/gmd" default="elements"
prefix="gmd"/>
<structure map-as="ca.gc.nrcan.mis_nap.data.base.BaseMdMetadata"/>
</mapping>
<mapping class="ca.gc.nrcan.mis_nap.data.base.BaseMdMetadata" abstract="true">
<namespace uri="http://www.isotc211.org/2005/gmd" default="elements"/>
<value name="id" get-method="getId" set-method="setId" style="attribute"
usage="optional"/>
<structure name="fileIdentifier" get-method="getFileidentifier"
set-method="setFileidentifier" usage="required" type="java.lang.String"
marshaller="ca.gc.nrcan.marshalling.CharacterStringMapper"
unmarshaller="ca.gc.nrcan.marshalling.CharacterStringMapper"/>
<structure name="language" get-method="getLanguage"
set-method="setLanguage"
usage="required" type="java.lang.String"
marshaller="ca.gc.nrcan.marshalling.CharacterStringMapper"
unmarshaller="ca.gc.nrcan.marshalling.CharacterStringMapper"/>
<collection field="objHierarchylevelnameSet"
create-type="java.util.HashSet">
<structure name="hierarchyLevelName"
type="ca.gc.nrcan.mis_nap.data.Hierarchylevelname"
marshaller="ca.gc.nrcan.marshalling.CharacterStringMapper"
unmarshaller="ca.gc.nrcan.marshalling.CharacterStringMapper"/>
</collection>
</mapping>
<mapping class="ca.gc.nrcan.mis_nap.data.Hierarchylevelname"
name="hierarchyLevelName">
<namespace uri="http://www.isotc211.org/2005/gmd" default="elements"
prefix="gmd"/>
<structure map-as="ca.gc.nrcan.mis_nap.data.base.BaseHierarchylevelname"/>
</mapping>
<mapping class="ca.gc.nrcan.mis_nap.data.base.BaseHierarchylevelname"
abstract="true">
<namespace uri="http://www.isotc211.org/2005/gmd" default="elements"
prefix="gmd"/>
<value name="id" get-method="getId" set-method="setId" style="attribute"
usage="optional"/>
<value name="hierarchyLevelName" get-method="getHierarchylevelname"
set-method="setHierarchylevelname"
usage="required"/>
</mapping>
</binding>
-------------xml file (collection section)-----------------
*** <gmd:hierarchyLevelName xsi:type="gmd:PT_FreeText_PropertyType">
<gco:CharacterString>021E05 - Sherbrooke</gco:CharacterString>
<gmd:PT_FreeText>
<gmd:textGroup>
<gmd:LocalisedCharacterString
locale="#frFR">Sherbrooke</gmd:LocalisedCharacterString>
</gmd:textGroup>
<gmd:textGroup>
<gmd:LocalisedCharacterString
locale="#anAN">Sherbrooke</gmd:LocalisedCharacterString>
</gmd:textGroup>
</gmd:PT_FreeText>
</gmd:hierarchyLevelName>***
<gmd:hierarchyLevelName xsi:type="gmd:PT_FreeText_PropertyType">
<gco:CharacterString>066P16 - Montreal</gco:CharacterString>
<gmd:PT_FreeText>
<gmd:textGroup>
<gmd:LocalisedCharacterString
locale="#frFR">Montréal</gmd:LocalisedCharacterString>
</gmd:textGroup>
<gmd:textGroup>
<gmd:LocalisedCharacterString
locale="#anAN">Montreal</gmd:LocalisedCharacterString>
</gmd:textGroup>
</gmd:PT_FreeText>
</gmd:hierarchyLevelName>
My unmarshaller takes the part between *** and convert it to String (it has to
be stored in the one field in the database). It works fine for structure like :
<gmd:fileIdentifier xsi:type="gmd:PT_FreeText_PropertyType">
<gco:CharacterString>SIM-PNA<gco:CharacterString>
<gmd:PT_FreeText>
<gmd:textGroup>
<gmd:LocalisedCharacterString locale="#frFR">Base de données SIM-PNA de
Sherbrooke</gmd:LocalisedCharacterString>
</gmd:textGroup>
<gmd:textGroup>
<gmd:LocalisedCharacterString locale="#anAN">SIM-PNA Database of
Sherbrooke</gmd:LocalisedCharacterString>
</gmd:textGroup>
</gmd:PT_FreeText>
</gmd:fileIdentifier>
Hope my english is enough clear : )
Thanks !
Marie-Eve
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
jibx-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jibx-users