Pergunta

2.4release , hibernate 3.3.2ga . while creating sessionfactory. I'm getting following error. Please provide me a solution

<bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
            <property name="dataSource" ref="erpUSDataSource" />

            <property name="annotatedClasses">
                <list>
                    <value>com.bean.OrderDetailsVO</value>
                    <value>com.bean.OrderVO</value>
                </list>

            </property>
            <property name="hibernateProperties">
                <props>
                    <prop key="hibernate.dialect">org.hibernate.dialect.SQLServer2008Dialect</prop>
                    <prop key="hibernate.show_sql">true</prop>
                    <!--  <prop key="hibernate.hbm2ddl.auto">update</prop> -->
                    <!-- <prop key="hibernate.use_outer_join">false</prop>
                    <prop key="hibernate.cache.provider_class">net.sf.ehcache.hibernate.SingletonEhCacheProvider</prop>
                    <prop key="hibernate.hibernate.cache.use_query_cache">true</prop> -->
                </props>
            </property>
     </bean>
     <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
        <property name="sessionFactory" ref="sessionFactory"/>
     </bean>

Caused by: org.hibernate.HibernateException: Could not instantiate connection provider [org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider] at org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator.instantiateExplicitConnectionProvider(ConnectionProviderInitiator.java:192) [hibernate-core-4.2.0.Final-redhat-1.jar:4.2.0.Final-redhat-1] at org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator.initiateService(ConnectionProviderInitiator.java:114) [hibernate-core-4.2.0.Final-redhat-1.jar:4.2.0.Final-redhat-1] at org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator.initiateService(ConnectionProviderInitiator.java:54) [hibernate-core-4.2.0.Final-redhat-1.jar:4.2.0.Final-redhat-1] at org.hibernate.service.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:69) [hibernate-core-4.2.0.Final-redhat-1.jar:4.2.0.Final-redhat-1] at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:176) [hibernate-core-4.2.0.Final-redhat-1.jar:4.2.0.Final-redhat-1] ... 90 more Caused by: java.lang.ClassCastException: org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider cannot be cast to org.hibernate.service.jdbc.connections.spi.ConnectionProvider at org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator.instantiateExplicitConnectionProvider(ConnectionProviderInitiator.java:189) [hibernate-core-4.2.0.Final-redhat-1.jar:4.2.0.Final-redhat-1] ... 94 more

Foi útil?

Solução 2

I have added Hibernate jars 4.0.1.Final including Hibernate Entitymanagaer, Hibernate-commons annotation, antlr 2.x,antlr-runtime2.x ..

My guess I got the problem due to not including above jars. I have added above jars my problem got resolved

com.bean.OrderDetailsVO com.bean.OrderVO org.hibernate.dialect.SQLServer2008Dialect true update</prop> --> false</prop> net.sf.ehcache.hibernate.SingletonEhCacheProvider</prop> true</prop> -->

Outras dicas

Judging from the stacktrace you are deploying on a newer JBoss server which comes, by default, shipped with hibernate4 as such hibernate3 classes aren't going to work.

Either you have to include your own hibernate library into your war file to use hibernate3 (and you probably will have to fix several other classloading issues then). Or you switch to use Hibernate4.

When using hibernate4 there is no more HibernateTemplate (as that should be considered deprecated since the release of hibernate 3.0.1 in 2006!). You might have to change some of your code if you rely heavily on the HibernateTemplate.

For your configuration simply switch to the hibernate4 class.

<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <property name="dataSource" ref="erpUSDataSource" />
    <property name="annotatedClasses">
        <list>
            <value>com.bean.OrderDetailsVO</value>
            <value>com.bean.OrderVO</value>
        </list>
    </property>
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.SQLServer2008Dialect</prop>
            <prop key="hibernate.show_sql">true</prop>
            <!--  <prop key="hibernate.hbm2ddl.auto">update</prop> -->
            <!-- <prop key="hibernate.use_outer_join">false</prop>
            <prop key="hibernate.cache.provider_class">net.sf.ehcache.hibernate.SingletonEhCacheProvider</prop>
            <prop key="hibernate.hibernate.cache.use_query_cache">true</prop> -->
        </props>
    </property>
</bean>

The same goes for the used HibernateTransactionManager which also needs to be switched to hibernate4, which is simply changing the package.

For more information on Spring and hibernate integration check the reference guide.

As mentioned there is no more HibernateTemplate instead you should use the plain Hibernate API to implement repositories. More info here.

You should already have proper transactionmanagement setup but just in case check this section of the reference guide.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top