2010-08-05 44 views
0

我使用JBoss 5.1.0.GA和HibernateHibernate和JBoss的SaxParser錯誤 - 衝突版本?

當我嘗試連接到數據庫,我收到以下錯誤

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) 

然後

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) 

我有以下的依存關係: -

hibernate-annotations 3.4.0.GA hibernate-commons-annotations 3.1.0.GA hibernate-core 3.3.0.SP1

我懷疑我在jboss lib中的一個jar和我的依賴中有一個jar有衝突。任何人都可以建議它可能是什麼?

+0

你打包休眠罐在你的應用程序?如果是,爲什麼? – 2010-08-05 10:26:37

+0

我們有範圍「編譯」的hibernate依賴關係。如果我刪除依賴關係,那麼mvn clean install會失敗(它在jaxb-schemagen上失敗:爲每個數據模型類生成一個「類不存在」消息) – Rainyday 2010-08-05 10:42:00

+0

如果使用'provided'作用域,該怎麼辦? – 2010-08-05 12:12:48

回答

0

當我在JBoss 5.0.1中運行Hibernate 4.0.0.CR6時遇到了同樣的錯誤。

由Hibernate來解析配置文件所需的解析器似乎是由JBoss的認可庫(/lib/endorsed/xercesImpl.jar我相信)提供和Hibernate的XML的API的依賴與他們在某種程度上干擾。

在生成的壓縮包(.war,在我的情況)中沒有打包xml-apis .jar竟然解決了這個問題。 要做到這一點我推翻依賴的範圍在項目生成存檔的.pom(覆蓋其他地方不會做,因爲提供範圍不傳遞):

<dependency> 
    <groupId>xml-apis</groupId> 
    <artifactId>xml-apis</artifactId> 
    <version>1.0.b2</version> 
    <scope>provided</scope> 
</dependency>