Hibernate和JBoss的SaxParser错误 - 冲突版本? [英] SaxParser errors with Hibernate and JBoss - conflicting versions?
问题描述
当我尝试连接到数据库时,我使用JBOSS 5.1.0.GA和Hibernate
出现以下错误:
10:21:03,042信息[版本] Hibernate Commons Annotations 3.1.0.GA
10:21:03,049 INFO [Configuration]从资源配置: /hibernate.cfg.xml
10:21:03,049 INFO [配置]配置资源:/hibernate.cfg.xml
10:21:03,077 INFO [STDOUT]警告:捕获的异常尝试使用SAX加载SAX XMLReader
10:21:03,077 INFO [STDOUT]警告:异常是:java.lang.ClassCastException:org.apache.xerces.parsers.SAXParser无法转换为org.xml.sax.XMLReader
10:21:03,077 INFO [STDOUT]警告:我将打印堆栈跟踪,然后使用默认的SAX解析器
10:21:03,077进行错误[STDERR] java.lang.ClassCastException:org.apache。 xerces.parsers.SAXParser无法转换为org.xml.sax.XMLReader
10:21:03,078错误[STDERR]位于org.xml.sax.helpers.XMLReaderFactory.loadClass(U n已知源)
10:21:03,078 ERROR [STDERR] at org.xml.sax.helpers.XMLReaderFactory.createXMLReader(Unknown Source)
10:21:03,078 ERROR [STDERR] at org.dom4j。 io.SAXHelper.createXMLReader(SAXHelper.java:83)
10:21:03,078 ERROR [STDERR] at org.dom4j.io.SAXReader.createXMLReader(SAXReader.java:894)
10:21: 03,078 ERROR [STDERR] at org.dom4j.io.SAXReader.getXMLReader(SAXReader.java:715)
10:21:03,078 ERROR [STDERR] at org.dom4j.io.SAXReader.read(SAXReader.java: 435)
10:21:03,078错误[STDERR]在org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1518)
然后
10:21:03,386信息[标准输出] 10:21:03,382 ERROR [DatabaseManager]错误初始化Hibernate
org.hibernate.HibernateException:无法解析配置:/hibernate.cfg.xml
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1528)
在org.hibernate.cfg.AnnotationConfiguration.do配置(AnnotationConfiguration.java:1035)
在org.hibernate.cfg.AnnotationConfiguration.doConfigure(AnnotationConfiguration.java:64)
在org.hibernate.cfg.Configuration.configure(Configuration.java:1462)
at org.hibernate.cfg.AnnotationConfiguration.configure(AnnotationConfiguration.java:1017)
at org.hibernate.cfg.AnnotationConfiguration.configure(AnnotationConfiguration.java:64)
at org.hibernate .cfg.Configuration.configure(Configuration.java:1448)
导致:org.dom4j.DocumentException:SAX2驱动程序类org.apache.xerces.parsers.SAXParser未实现XMLReader嵌套异常:SAX2驱动程序类org.apache.xerces.parsers.SAXParser未在org.dom4j.io.SAXReader.read(SAXReader.java:484)上实现XMLReader
(org.hibernate.cfg)
.Configuration.doConfigure(Configuration.java:1518)
我有以下依赖关系: -
hibernate-annotations 3.4.0.GA
hibernate-commons-annotations 3.1.0.GA
hibernate-core 3.3.0.SP1
我怀疑我之间有冲突jboss库和一个在我的依赖项中。任何人都可以推荐它可能是什么?
我试图在JBoss中运行Hibernate 4.0.0.CR6时遇到了相同的错误5.0.1。
Hibernate需要解析配置文件的解析器似乎是由jboss支持的库提供的( /lib/endorsed/xercesImpl.jar em>我相信),并且hibernate的xml-apis依赖以某种方式干扰了它们。
没有在生成的压缩文件中打包xml-apis .jar(在我的情况下是.war)解决问题。
为此,我覆盖了生成存档的项目的.pom中的依赖项的范围(在其他地方覆盖不会执行,因为提供的
< dependency>
< groupId> xml-apis< / groupId>
< artifactId> xml-apis< / artifactId>
< version> 1.0.b2< / version>
< scope>提供< / scope>
< /依赖关系>
I am using JBOSS 5.1.0.GA and Hibernate
when I try to connect to the database I get the following errors
10:21:03,042 INFO [Version] Hibernate Commons Annotations 3.1.0.GA
10:21:03,049 INFO [Configuration] configuring from resource: /hibernate.cfg.xml
10:21:03,049 INFO [Configuration] Configuration resource: /hibernate.cfg.xml
10:21:03,077 INFO [STDOUT] Warning: Caught exception attempting to use SAX to load a SAX XMLReader
10:21:03,077 INFO [STDOUT] Warning: Exception was: java.lang.ClassCastException: org.apache.xerces.parsers.SAXParser cannot be cast to org.xml.sax.XMLReader
10:21:03,077 INFO [STDOUT] Warning: I will print the stack trace then carry on using the default SAX parser
10:21:03,077 ERROR [STDERR] java.lang.ClassCastException: org.apache.xerces.parsers.SAXParser cannot be cast to org.xml.sax.XMLReader
10:21:03,078 ERROR [STDERR] at org.xml.sax.helpers.XMLReaderFactory.loadClass(Unknown Source)
10:21:03,078 ERROR [STDERR] at org.xml.sax.helpers.XMLReaderFactory.createXMLReader(Unknown Source)
10:21:03,078 ERROR [STDERR] at org.dom4j.io.SAXHelper.createXMLReader(SAXHelper.java:83)
10:21:03,078 ERROR [STDERR] at org.dom4j.io.SAXReader.createXMLReader(SAXReader.java:894)
10:21:03,078 ERROR [STDERR] at org.dom4j.io.SAXReader.getXMLReader(SAXReader.java:715)
10:21:03,078 ERROR [STDERR] at org.dom4j.io.SAXReader.read(SAXReader.java:435)
10:21:03,078 ERROR [STDERR] at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1518)
then
10:21:03,386 INFO [STDOUT] 10:21:03,382 ERROR [DatabaseManager] Error intialising Hibernate
org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1528)
at org.hibernate.cfg.AnnotationConfiguration.doConfigure(AnnotationConfiguration.java:1035)
at org.hibernate.cfg.AnnotationConfiguration.doConfigure(AnnotationConfiguration.java:64)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1462)
at org.hibernate.cfg.AnnotationConfiguration.configure(AnnotationConfiguration.java:1017)
at org.hibernate.cfg.AnnotationConfiguration.configure(AnnotationConfiguration.java:64)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1448)
Caused by: org.dom4j.DocumentException: SAX2 driver class org.apache.xerces.parsers.SAXParser does not implement XMLReader Nested exception: SAX2 driver class org.apache.xerces.parsers.SAXParser does not implement XMLReader
at org.dom4j.io.SAXReader.read(SAXReader.java:484)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1518)
I have the following dependencies:-
hibernate-annotations 3.4.0.GA hibernate-commons-annotations 3.1.0.GA hibernate-core 3.3.0.SP1
I suspect I have a conflict between a jar in the jboss lib and one in my dependencies. can anyone suggest what it might be?
I got about same error when trying to run Hibernate 4.0.0.CR6 in JBoss 5.0.1.
The parser needed by Hibernate to parse configuration files seems to be provided by jboss endorsed libraries (/lib/endorsed/xercesImpl.jar I believe)and hibernate's xml-apis dependency somehow interfered with them.
Not packing xml-apis .jar in generated archive (.war in my case) turned out to fix the problem. To do that I overrode the scope of the dependency in the .pom of the project generating the archive (overriding anywhere else wouldn't do because provided scope is not transitive):
<dependency>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
<version>1.0.b2</version>
<scope>provided</scope>
</dependency>
这篇关于Hibernate和JBoss的SaxParser错误 - 冲突版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!