0

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

Anil M
  • 3
  • 1
  • 7
  • You expect a hibernate3 class to be cast the hibernate class, that is never going to work. Use the proper beans in your xml. Use the hibernate4 instead of the hibernate3 beans. – M. Deinum Jan 23 '14 at 07:40
  • can you suggest me proper hibernate version for spring3.2.4.Release? – Anil M Jan 23 '14 at 07:45

2 Answers2

0

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.

M. Deinum
  • 115,695
  • 22
  • 220
  • 224
  • thank you for yor support,....... can You suggest me alternate to HibernateTemplate? – Anil M Jan 23 '14 at 07:57
  • by using HibernateTransactionManager How can we perform saving operation...............? – Anil M Jan 23 '14 at 08:40
  • See http://docs.spring.io/spring/docs/3.2.7.BUILD-SNAPSHOT/spring-framework-reference/htmlsingle/#orm-hibernate – M. Deinum Jan 23 '14 at 08:46
  • How can we perform CRUD operations using Hibernate4 .. I want the simplest and easyway.. ? I think hibernateTransactionManager is not alternate of HibernateTemplate.. How can we use HibernateTemplate in Hibernate4..? – Anil M Jan 23 '14 at 09:04
  • There is no `HibernateTemplate` for hibernate4. Read the documentation links I put in the answer... – M. Deinum Jan 23 '14 at 09:19
  • My problem was solved.. I have added antlr.jars It is working fine. the problem is with the jars which i have added.. thanks – Anil M Jan 23 '14 at 11:41
0

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> -->

Anil M
  • 3
  • 1
  • 7