1

当我尝试 config hibernate 和 java app (how Jira service) ,我有这个错误:

Warning: Caught exception attempting to use SAX to load a SAX XMLReader 
[INFO] [talledLocalContainer] Warning: Exception was: java.lang.ClassCastException:org.apache.xerces.parsers.SAXParser cannot be cast to org.xml.sax.XMLReader
[INFO] [talledLocalContainer] Warning: I will print the stack trace then carry on using the default SAX parser
[INFO] [talledLocalContainer] java.lang.ClassCastException: org.apache.xerces.parsers.SAXParser cannot be cast to org.xml.sax.XMLReader
[INFO] [talledLocalContainer]   at org.xml.sax.helpers.XMLReaderFactory.loadClass(XMLReaderFactory.java:243)
[INFO] [talledLocalContainer]   at org.xml.sax.helpers.XMLReaderFactory.createXMLReader(XMLReaderFactory.java:194)
[INFO] [talledLocalContainer]   at org.dom4j.io.SAXHelper.createXMLReader(SAXHelper.java:83)
[INFO] [talledLocalContainer]   at org.dom4j.io.SAXReader.createXMLReader(SAXReader.java:894)
[INFO] [talledLocalContainer]   at org.dom4j.io.SAXReader.getXMLReader(SAXReader.java:715)
[INFO] [talledLocalContainer]   at org.dom4j.io.SAXReader.read(SAXReader.java:435)
[INFO] [talledLocalContainer]   at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1518)

-->

Caused by: org.hibernate.HibernateException: Could not parse configuration: hibernate.cfg.xml
[INFO] [talledLocalContainer]   at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1528)
[INFO] [talledLocalContainer]   at org.hibernate.cfg.AnnotationConfiguration.doConfigure(AnnotationConfiguration.java:1035)
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
[INFO] [talledLocalContainer]   at org.dom4j.io.SAXReader.read(SAXReader.java:484)
[INFO] [talledLocalContainer]   at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1518)
[INFO] [talledLocalContainer]   ... 14 more

-->

....我的 hibernate.cfg.xml :

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD//EN"
    "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/navision</property>
        <property name="hibernate.connection.username">admin</property>
        <property name="hibernate.connection.password">admin</property>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>
        <property name="hibernate.show_sql">false</property>
        <property name="hibernate.cache.use_query_cache">false</property>
        <property name="hibernate.cache.use_second_level_cache">false</property>
        <property name="hibernate.generate_statistics">false</property>
        <property name="hibernate.c3p0.acquire_increment">1</property>
        <property name="hibernate.c3p0.idle_test_period">100</property>
        <property name="hibernate.c3p0.max_size">100</property>
        <property name="hibernate.c3p0.max_statements">0</property>
        <property name="hibernate.c3p0.min_size">10</property>
        <property name="hibernate.c3p0.timeout">100</property>
        <property name="connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
        <property name="hbm2ddl.auto">update</property>
    </session-factory>

-->

当我尝试为 db 初始化 SessionFactory 时出现此错误:

ourSessionFactory = new AnnotationConfiguration().configure("hibernate.cfg.xml").addAnnotatedClass(Navision.class).buildSessionFactory(); 

-->

4

2 回答 2

0

问题已解决。我发现了一些以前没有见过的因素。这些是包含在自定义库中的解析器,hibernate.core、dom4j 和其他。

于 2012-09-24T13:19:22.087 回答
0

包括其他版本的 xerxesImpl 通常是痛苦的秘诀。从您的应用程序中删除任何 xercesImpl 或 xml-apis jar。

于 2012-09-19T18:45:59.903 回答