且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

java.lang.ClassCastException:org.apache.xerces.parsers.SAXParser无法转换为org.xml.sax.XMLReader Hibernate

更新时间:2023-11-06 18:51:10

删除loadtimeweaver属性后,它工作正常。



< property name =loadTimeWeaver>

< bean class =org.faces.controller。 jpa.JpaLoadTimeWeaver/&GT;
< / property>



这个链接表明,尽管它已经很旧了,

https://jira.springsource.org/browse/ SPR-2596


I am working on a project with Hibernate JPA /spring.

It throws the following exception. After doing some reading I removed all the xml-apis from dependencies but it throws the same error. Any ideas ??

java.lang.ClassCastException: org.apache.xerces.parsers.SAXParser cannot be cast to org.xml.sax.XMLReader
    at org.xml.sax.helpers.XMLReaderFactory.loadClass(XMLReaderFactory.java:199)
    at org.xml.sax.helpers.XMLReaderFactory.createXMLReader(XMLReaderFactory.java:150)
    at org.dom4j.io.SAXHelper.createXMLReader(SAXHelper.java:83)
    at org.dom4j.io.SAXReader.createXMLReader(SAXReader.java:894)
    at org.dom4j.io.SAXReader.getXMLReader(SAXReader.java:715)
    at org.dom4j.io.SAXReader.setFeature(SAXReader.java:218)
    at org.hibernate.internal.util.xml.MappingReader.setValidationFor(MappingReader.java:114)
    at org.hibernate.internal.util.xml.MappingReader.readMappingDocument(MappingReader.java:77)
    at org.hibernate.cfg.Configuration.add(Configuration.java:478)
    at org.hibernate.cfg.Configuration.add(Configuration.java:474)
    at org.hibernate.cfg.Configuration.add(Configuration.java:647)
    at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:685)
    at org.hibernate.ejb.Ejb3Configuration.addClassesToSessionFactory(Ejb3Configuration.java:1248)
    at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:1048)
    at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:693)
    at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:73)
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:225)
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:310)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)

while I am trying to initialise the web context in jetty web server it throw the above exception.[Spring (3.0.6.Release) & hibernate (4.1.10.final) ]

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:util="http://www.springframework.org/schema/util"
   xmlns:context="http://www.springframework.org/schema/context"
   xmlns:tx="http://www.springframework.org/schema/tx"
   xmlns:p="http://www.springframework.org/schema/p"
   xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context-3.0.xsd
       http://www.springframework.org/schema/tx
       http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">

<import resource="classpath*:/META-INF/spring-orchestra-init.xml"/>

<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="entityManagerFactory" ref="entityManagerFactory" />
        </bean>

<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>

<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>

<tx:annotation-driven transaction-manager="transactionManager"/>

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"    
      p:persistenceUnitName="persistenceUnit">
    <property name="dataSource" ref="dataSource"/>
    <property name="jpaDialect">
        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect"/>
    </property>
    <property name="jpaVendorAdapter">
        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
            <property name="showSql" value="true"/>
            <property name="generateDdl" value="false"/>
        </bean>
    </property>
    <property name="loadTimeWeaver">
        <bean class="org.faces.controller.jpa.JpaLoadTimeWeaver"/>
    </property>

</bean>

<bean class="org.springframework.beans.factory.config.CustomScopeConfigurer">
    <property name="scopes">
        <map>
            <entry key="conversation.access">
                <bean class="org.apache.myfaces.orchestra.conversation.spring.SpringConversationScope">
                    <property name="advices">
                        <list>
                            <ref bean="persistentContextConversationInterceptor" />
                        </list>
                    </property>
                </bean>
            </entry>
        </map>
    </property>
</bean>

<bean id="jpaPersistentContextFactory" class="org.apache.myfaces.orchestra.conversation.spring.JpaPersistenceContextFactory">
    <property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<bean id="persistentContextConversationInterceptor" class="org.apache.myfaces.orchestra.conversation.spring.PersistenceContextConversationInterceptor">
    <property name="persistenceContextFactory" ref="jpaPersistentContextFactory" />
</bean>

<bean name="org.apache.myfaces.orchestra.conversation.AccessScopeManagerConfiguration"
      class="org.apache.myfaces.orchestra.conversation.AccessScopeManagerConfiguration"
      scope="singleton" lazy-init="true">

    <property name="ignoreViewIds">
        <set>
            <value>/__ADFv__.xhtml</value>
        </set>
    </property>
</bean>
<bean id="dataSource"
    class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
    <property name="url" value="jdbc:oracle:thin:@rum:1541:CHEZTST" />
    <property name="username" value="username" />
    <property name="password" value="password" />
</bean>

After removing the loadtimeweaver property it worked fine.

<property name="loadTimeWeaver">
<bean class="org.faces.controller.jpa.JpaLoadTimeWeaver"/> </property>

this is the link that shows that, although it is quite old it works

https://jira.springsource.org/browse/SPR-2596