2

I am trying to get hyperjaxb to process a real schema. I downloaded and unzipped the hyperjaxb maven project from this link and then navigated to the root directory using cmd.exe and tested it with the sample data by running mvn clean install to make sure that it works with the example schema. I then replaced the schema.xsd, po.xml, and bindings.xjb files with a stripped down version of actual shematics so that I can prepare to run a real app through the above-linked hyperjaxb project. I then ran mvn clean install again. However, I am getting the following error message:

[ERROR] Error while parsing schema(s).Location 
[ file:/C:/path/to/src/main/resources/bindings.xjb{25,53}].
com.sun.istack.SAXParseException2; systemId: 
file:/C:/path/to/src/main/resources/bindings.xjb; lineNumber: 25; columnNumber: 53; 
XPath evaluation of "xs:complexType[@name='Any']" results in empty target node  

from the replacement bindings.xjb file that you can read at this link. using the schema.xsd file at this link, and the po.xml that you can read at this link.

The relevant section of bindings.xjb is:

<jaxb:bindings node="xs:complexType[@name='Any']">
    <hj:entity>
        <orm:table name="any"/>
    </hj:entity>
</jaxb:bindings>

The definition of the ANY complexType in schema.xsd is:

<xs:complexType name="ANY"><!-- abstract="true">-->
  <xs:annotation>
    <xs:documentation>
        Some documentation.
    </xs:documentation>
  </xs:annotation>
  <xs:attribute name="nullFlavor" type="NullFlavor" use="optional">
    <xs:annotation>
      <xs:documentation>
           Some other documentation.
        </xs:documentation>
    </xs:annotation>
  </xs:attribute>
</xs:complexType>  

Note that the complete code is in the links above. How can I resolve this error?

lexicore
  • 42,748
  • 17
  • 132
  • 221
CodeMed
  • 9,527
  • 70
  • 212
  • 364

1 Answers1

2

You should use below configuration..

<jaxb:bindings node="//xs:complexType[@name='ANY']">
    <hj:entity>
        <orm:table name="any"/>
    </hj:entity>
</jaxb:bindings>

An example could you find in this my answer of another topic. https://stackoverflow.com/a/24953369/3364187


I tried your project, this configuration works fine. Let me know if works in your environment.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<jaxb:bindings
    version="2.1"
    xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:hj="http://hyperjaxb3.jvnet.org/ejb/schemas/customizations"
    xmlns:orm="http://java.sun.com/xml/ns/persistence/orm"
    jaxb:extensionBindingPrefixes="hj orm">

    <jaxb:bindings schemaLocation="schema.xsd" node="/xs:schema">
        <jaxb:globalBindings generateIsSetMethod="true"/>
        <jaxb:schemaBindings>
            <jaxb:package name="org.jvnet.hyperjaxb3.ejb.tests.pocustomized"/>
        </jaxb:schemaBindings>
        <jaxb:bindings node="//xs:complexType[@name='InfrastructureRoot.typeId']">
            <hj:entity>
                <orm:table name="typeId"/>
            </hj:entity>
        </jaxb:bindings>
        <jaxb:bindings node="//xs:complexType[@name='II']">
            <hj:entity>
                <orm:table name="II"/>
            </hj:entity>
        </jaxb:bindings>
        <jaxb:bindings node="//xs:complexType[@name='ANY']">
            <hj:entity>
                <orm:table name="any"/>
            </hj:entity>
        </jaxb:bindings>
    </jaxb:bindings>


</jaxb:bindings>

In brief for each node was missing //

Selects nodes in the document from the current node that match the selection no matter where they are

and the complex type isn't "Any" but "ANY", then, the correct node is @name='ANY'

Community
  • 1
  • 1
Xstian
  • 8,184
  • 10
  • 42
  • 72
  • Thank you so much for looking into this. I just tried your change, but it results in the same exact error. What else might be causing this? – CodeMed Oct 16 '14 at 17:34
  • Can you add more details of XSD? – Xstian Oct 16 '14 at 17:35
  • 1
    I posted the entire xsd file along with all other relevant files to completely reproduce the problem in the links in my original posting above. The xsd file is 259 lines, so I did not want to pollute the posting with its entirety. But someone could reproduce the problem in a local machine in a few minutes using all the links above. – CodeMed Oct 16 '14 at 17:37
  • +1 and thank you for solving my problem. I am new to `hyperjaxb`, `jaxb`, and `bindings.xjb` files. I need to scale up the input files so that they generate the several hundred classes that get generated when I run my full schema through `JAXB`. Are you willing to briefly state why your solution works, and point me to someplace I might learn how to write bindings.xjb? Will I need to create a separate `bindings` tag for every one of the several hundred entities? `JAXB` makes all my entities without requiring the above bindings. – CodeMed Oct 16 '14 at 18:08
  • 1
    I suggest you [this link](http://www.w3schools.com/xpath/xpath_syntax.asp) where is explain in brief the syntax of xpath. instead [here a link](http://docs.oracle.com/cd/E17802_01/webservices/webservices/docs/2.0/tutorial/doc/JAXBUsing4.html) where is explain how to make a binding file. Yes, i think that you must create a bindings for each entity that you want customize. I added more details of the solution. – Xstian Oct 16 '14 at 18:18
  • 1
    @Xstian You need bindings if and ONLY if you need to customize, for instance to change the table name. Otherwise Hyperjaxb will generate some reasonable names by default. All of the customizations are purely optional. http://confluence.highsource.org/display/HJ3/Customization+Guide#CustomizationGuide-Introduction – lexicore Oct 16 '14 at 18:37
  • @lexicore Sorry you're right, I meant what you said, I should probably clarify the meaning of "customize" :) – Xstian Oct 16 '14 at 18:41
  • @Xstian You also don't need `//` before `xs:complexType`. `node` gives an XPath relative to the `node` of the parent `bindings`. So for the top-level complex types you don't need `//`. `//` stands for "somewhere" in the document and it is way to broad. – lexicore Oct 16 '14 at 18:43
  • @Xstian Please do, otherwise it makes an impression that you need a `binding` for each and every entity. Which is not correct. Thank you. :) – lexicore Oct 16 '14 at 18:44
  • @Xstian I plugged my full schema into the same project, and I am getting a namespace error that I do not get when I run my identical full schema through JAXB. I think the problem has to do with the tools that hyperjaxb uses. I posted the problem in another question. Are you willing to help me with that one also? here is the link: http://stackoverflow.com/questions/26413793/unsupported-binding-namespace – CodeMed Oct 16 '14 at 21:02