Thursday, July 26, 2018

XML-20116: (Warning) Entity already defined, using the first definition.

I’ve been pulling my hair out seeing the following error message while trying to make a simple XSLT transformation in my spring application.
XML-20116: (Warning) Entity 'tablemodel' already defined, using the first definition.
 at oracle.xml.parser.v2.XMLError.flushErrorHandler(XMLError.java:425)
 at oracle.xml.parser.v2.XMLError.flushErrors1(XMLError.java:290)
 at oracle.xml.parser.v2.XMLReader.scanNameChars(XMLReader.java:1306)
 at oracle.xml.parser.v2.XMLReader.scanQName(XMLReader.java:2204)
 at oracle.xml.parser.v2.XMLExternalReader.scanQName(XMLExternalReader.java:404)
 at oracle.xml.parser.v2.NonValidatingParser.parseAttrDecl(NonValidatingParser.java:1024)
 at oracle.xml.parser.v2.NonValidatingParser.parseAttlistDecl(NonValidatingParser.java:989)
 at oracle.xml.parser.v2.NonValidatingParser.parseMarkupDecl(NonValidatingParser.java:819)
 at oracle.xml.parser.v2.NonValidatingParser.parseMarkupDecl(NonValidatingParser.java:843)
 at oracle.xml.parser.v2.NonValidatingParser.parseDoctypeDecl(NonValidatingParser.java:644)
 at oracle.xml.parser.v2.NonValidatingParser.parseProlog(NonValidatingParser.java:435)
 at oracle.xml.parser.v2.NonValidatingParser.parseDocument(NonValidatingParser.java:393)
 at oracle.xml.parser.v2.XMLParser.parse(XMLParser.java:236)
Even though I’ve explicitly instructed my app to use Saxon library, obviously xml parser from oracle gets in the way, but why? It turns out that when you bring the oracle jdbc driver dependency via maven using Oracle's maven repo, it transitively gets other libraries which causes this problem when parsing the XMLs. I just excluded the transitive dependencies for the oracle driver and everything works just fine. I don't think those extra libs are necessary at all at runtime. If you have this in your pom:
<dependency>
    <groupid>com.oracle.jdbc</groupid>
    <artifactid>ojdbc7</artifactid>
    <version>12.1.0.2</version>
</dependency>
Just exclude the transitive dependencies for the oracle driver and everything works just fine.
<dependency>
    <groupid>com.oracle.jdbc</groupid>
    <artifactid>ojdbc7</artifactid>
    <version>12.1.0.2</version>
    <exclusions>
        <exclusion>
            <artifactid>xmlparserv2</artifactid>
            <groupid>com.oracle.jdbc</groupid>
        </exclusion>
    </exclusions>
</dependency>
This is the dependency tree by the way
  • ojdbc7 : 12.1.0.2
  • xdb6 : 12.1.0.2
  • orai18n : 12.1.0.2
  • xmlparserv2 : 12.1.0.2 -> obvious culprit
  • oraclepki : 12.1.0.2
  • osdt_cert : 12.1.0.2
  • osdt_core : 12.1.0.2

Happy coding!

No comments: