Quantcast

troubleshoot "trying to create the same field twice" error?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

troubleshoot "trying to create the same field twice" error?

metro-3
I am trying to use xjc from JAXB 2.1.7 to generate Java code for the HL7 CDA R2 format. Unfortunately, there appears to be an error in one of the XML Schema files and so xjc fails with this exception.

Exception in thread "main" java.lang.IllegalArgumentException: trying to create the same field twice: id
        at com.sun.codemodel.JDefinedClass.field(JDefinedClass.java:419)
        at com.sun.codemodel.JDefinedClass.field(JDefinedClass.java:390)
        at com.sun.tools.xjc.generator.bean.field.AbstractFieldWithVar.createField(AbstractFieldWithVar.java:71)
        at com.sun.tools.xjc.generator.bean.field.SingleField.<init>(SingleField.java:89)
        at com.sun.tools.xjc.generator.bean.field.SingleField.<init>(SingleField.java:76)
        at sun.reflect.GeneratedConstructorAccessor10.newInstance(Unknown Source)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
        at java.lang.reflect.Constructor.newInstance(Unknown Source)
        at com.sun.tools.xjc.generator.bean.field.GenericFieldRenderer.generate(GenericFieldRenderer.java:64)
        at com.sun.tools.xjc.generator.bean.field.DefaultFieldRenderer.generate(DefaultFieldRenderer.java:75)
        at com.sun.tools.xjc.generator.bean.BeanGenerator.generateFieldDecl(BeanGenerator.java:744)
        at com.sun.tools.xjc.generator.bean.BeanGenerator.generateClassBody(BeanGenerator.java:532)
        at com.sun.tools.xjc.generator.bean.BeanGenerator.<init>(BeanGenerator.java:234)
        at com.sun.tools.xjc.generator.bean.BeanGenerator.generate(BeanGenerator.java:174)
        at com.sun.tools.xjc.model.Model.generateCode(Model.java:286)
        at com.sun.tools.xjc.Driver.run(Driver.java:343)
        at com.sun.tools.xjc.Driver.run(Driver.java:191)
        at com.sun.tools.xjc.Driver._main(Driver.java:116)
        at com.sun.tools.xjc.Driver.access$000(Driver.java:74)
        at com.sun.tools.xjc.Driver$1.run(Driver.java:96)

How can I troubleshoot the problem further to tell exactly what is wrong? Unfortunately it doesn't show the exact location of the error, or even the file name, so I'm at a loss about where to start.

The XML Schema files can be downloaded here: http://www.hl7.org/v3ballot/html/infrastructure/cda/cda.htm#CDA_Schema. The CDA.xsd file is the top level one, which includes all of the others.
[Message sent by forum member 'nradov' (nradov)]

http://forums.java.net/jive/thread.jspa?messageID=278619

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: troubleshoot "trying to create the same field twice" error?

Jitendra Kotamraju
For tracking purpose, you may to file a bug on JAXB

Jitu
[hidden email] wrote:

> I am trying to use xjc from JAXB 2.1.7 to generate Java code for the HL7 CDA R2 format. Unfortunately, there appears to be an error in one of the XML Schema files and so xjc fails with this exception.
>
> Exception in thread "main" java.lang.IllegalArgumentException: trying to create the same field twice: id
>         at com.sun.codemodel.JDefinedClass.field(JDefinedClass.java:419)
>         at com.sun.codemodel.JDefinedClass.field(JDefinedClass.java:390)
>         at com.sun.tools.xjc.generator.bean.field.AbstractFieldWithVar.createField(AbstractFieldWithVar.java:71)
>         at com.sun.tools.xjc.generator.bean.field.SingleField.<init>(SingleField.java:89)
>         at com.sun.tools.xjc.generator.bean.field.SingleField.<init>(SingleField.java:76)
>         at sun.reflect.GeneratedConstructorAccessor10.newInstance(Unknown Source)
>         at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
>         at java.lang.reflect.Constructor.newInstance(Unknown Source)
>         at com.sun.tools.xjc.generator.bean.field.GenericFieldRenderer.generate(GenericFieldRenderer.java:64)
>         at com.sun.tools.xjc.generator.bean.field.DefaultFieldRenderer.generate(DefaultFieldRenderer.java:75)
>         at com.sun.tools.xjc.generator.bean.BeanGenerator.generateFieldDecl(BeanGenerator.java:744)
>         at com.sun.tools.xjc.generator.bean.BeanGenerator.generateClassBody(BeanGenerator.java:532)
>         at com.sun.tools.xjc.generator.bean.BeanGenerator.<init>(BeanGenerator.java:234)
>         at com.sun.tools.xjc.generator.bean.BeanGenerator.generate(BeanGenerator.java:174)
>         at com.sun.tools.xjc.model.Model.generateCode(Model.java:286)
>         at com.sun.tools.xjc.Driver.run(Driver.java:343)
>         at com.sun.tools.xjc.Driver.run(Driver.java:191)
>         at com.sun.tools.xjc.Driver._main(Driver.java:116)
>         at com.sun.tools.xjc.Driver.access$000(Driver.java:74)
>         at com.sun.tools.xjc.Driver$1.run(Driver.java:96)
>
> How can I troubleshoot the problem further to tell exactly what is wrong? Unfortunately it doesn't show the exact location of the error, or even the file name, so I'm at a loss about where to start.
>
> The XML Schema files can be downloaded here: http://www.hl7.org/v3ballot/html/infrastructure/cda/cda.htm#CDA_Schema. The CDA.xsd file is the top level one, which includes all of the others.
> [Message sent by forum member 'nradov' (nradov)]
>
> http://forums.java.net/jive/thread.jspa?messageID=278619
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>  


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: troubleshoot "trying to create the same field twice" error?

metro-3
In reply to this post by metro-3
Error in Schema POCD_MT000040.xsd

Two Problems As Fallows :

[b]1.)[/b]

id field is taken as attr as well as element [b](ID and id is same)[/b]

Check complex type POCD_MT000040.ObservationMedia [b](line no 787)[/b]


[i]<xs:complexType name="POCD_MT000040.ObservationMedia">
                <xs:sequence>
                        <xs:element name="realmCode" type="CS" minOccurs="0" maxOccurs="unbounded"/>
                        <xs:element name="typeId" type="POCD_MT000040.InfrastructureRoot.typeId" minOccurs="0"/>
                        <xs:element name="templateId" type="II" minOccurs="0" maxOccurs="unbounded"/>
                        [b]<xs:element name="id" type="II" minOccurs="0" maxOccurs="unbounded"/>[/b]
                        <xs:element name="languageCode" type="CS" minOccurs="0"/>
                        <xs:element name="value" type="ED"/>
                        <xs:element name="subject" type="POCD_MT000040.Subject" minOccurs="0"/>
                        <xs:element name="specimen" type="POCD_MT000040.Specimen" minOccurs="0" maxOccurs="unbounded"/>
                        <xs:element name="performer" type="POCD_MT000040.Performer2" minOccurs="0" maxOccurs="unbounded"/>
                        <xs:element name="author" type="POCD_MT000040.Author" minOccurs="0" maxOccurs="unbounded"/>
                        <xs:element name="informant" type="POCD_MT000040.Informant12" minOccurs="0" maxOccurs="unbounded"/>
                        <xs:element name="participant" type="POCD_MT000040.Participant2" minOccurs="0" maxOccurs="unbounded"/>
                        <xs:element name="entryRelationship" type="POCD_MT000040.EntryRelationship" minOccurs="0" maxOccurs="unbounded"/>
                        <xs:element name="reference" type="POCD_MT000040.Reference" minOccurs="0" maxOccurs="unbounded"/>
                        <xs:element name="precondition" type="POCD_MT000040.Precondition" minOccurs="0" maxOccurs="unbounded"/>
                </xs:sequence>
                [b]<xs:attribute name="ID1" type="xs:ID"/>[/b]
                <xs:attribute name="nullFlavor" type="NullFlavor" use="optional"/>
                <xs:attribute name="classCode" type="ActClassObservation" use="required"/>
                <xs:attribute name="moodCode" type="ActMood" use="required"/>
        </xs:complexType>[/i]


So change name ID to ID1 or any thing it will works fine.
Search for same bug in that xsd u will find it 3-4 times.

[b] 2.)[/b]One more problem in that
replace
[b]ActClinicalDocument [/b] with [b]ActClassClinicalDocument[/b] in same file

Try above changes it will work

Thanks
[Message sent by forum member 'yadavkj' (yadavkj)]

http://forums.java.net/jive/thread.jspa?messageID=278722

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: troubleshoot "trying to create the same field twice" error?

metro-3
Thanks for identifying the problems. I posted a new issue to request that line numbers be displayed for errors like this.

https://jaxb.dev.java.net/issues/show_bug.cgi?id=512
[Message sent by forum member 'nradov' (nradov)]

http://forums.java.net/jive/thread.jspa?messageID=278910

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: troubleshoot "trying to create the same field twice" error?

metro-3
In reply to this post by metro-3
The problem with this hack is that CDA document instances may no longer be valid since you are changing schema itself.  A better solution is to use JAXB binding customizations to tell JAXB to bind the ID attribute to a different name in the generated Java code.  For each of these three ID attributes add this annotation:

<xs:attribute name="ID" type="xs:ID">
   <xs:annotation>
      <xs:appinfo>
         <jaxb:property name="ID1"/>
      </xs:appinfo>
   </xs:annotation>
</xs:attribute>

And at the top of the POCD_MT000040.xsd add JAXB namespaces so it looks like this:

<xs:schema targetNamespace="urn:hl7-org:v3"
        xmlns:mif="urn:hl7-org:v3/mif"
        xmlns="urn:hl7-org:v3"
        xmlns:xs="http://www.w3.org/2001/XMLSchema"
        xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
        xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
        elementFormDefault="qualified"
        jaxb:version="1.0"
        jaxb:extensionBindingPrefixes="xjc">

Finally be sure to add -extension switch to xjc, and poof, now you get a workable set of JAXB Java objects that works with CDA schema compliant document instances.
[Message sent by forum member 'mgpotter' (mgpotter)]

http://forums.java.net/jive/thread.jspa?messageID=303995

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Loading...