2

My problem is same as this one - java.lang.NoSuchMethodError: org.hibernate.SessionFactory.openSession()Lorg/hibernate/classic/Session

I get the following exception while using Spring JDBCTemplate.

java.lang.NoSuchMethodError: org.hibernate.Session.connection()Ljava/sql/Connection;

The accepted answer in the link above, recommends downgrading Hibernate to a version supported by Spring.

This is not acceptable to me as I need the latest version of Hibernate to use its new features (and also benefit from bug fixes).

Is there a way to get it to work without downgrading hibernate?

6
  • so which versions of Spring and Hibernate do you currently have? Commented Mar 28, 2015 at 13:33
  • Spring is up to version 4.1.6; Hibernate's at 4.3.8. Commented Mar 28, 2015 at 13:36
  • 2
    @duffymo you could go further: why Java? What is it doing for you that C or assembler cannot? Commented Mar 28, 2015 at 13:37
  • Spring 3.0.5 and Hibernate is 4.3.8. I can upgrade Spring but there are several other projects that inter-operate and all of them are using Spring 3.0.5. 3.x to 4.x migration would break code in many places and necessitate code change. I don't have want to do that at this time...maybe later when we do a complete overhaul. Besides, why does Spring even have dependency on Hibernate? I was expecting Spring JDBC to be dependent only on JDBC. Commented Mar 28, 2015 at 13:55
  • You can't expect a really really old version of Spring to be automatically compatible with the lastest non-compatible changes in Hibernate. Regarding the second part of your comment: what is the complete stack trace of the exception? spring-jdbc doesn't have any dependency on Hibernate, and I doubt the error you get comes from spring-jdbc code. Commented Mar 28, 2015 at 14:08

2 Answers 2

1

I got this because I had upgraded from Hibernate4 to Hibernate 5 but still had a reference to 4 in the web.xml.

Was:

<filter>
    <filter-name>hibernateFilter</filter-name>
    <filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>
    <init-param>
        <param-name>sessionFactoryBeanName</param-name>
        <param-value>sessionFactory</param-value>
    </init-param>
</filter>

changed to:

<filter>
    <filter-name>hibernateFilter</filter-name>
    <filter-class>org.springframework.orm.hibernate5.support.OpenSessionInViewFilter</filter-class>
    <init-param>
        <param-name>sessionFactoryBeanName</param-name>
        <param-value>sessionFactory</param-value>
    </init-param>
</filter>
Sign up to request clarification or add additional context in comments.

Comments

0

The transaction manager being used was JPA transaction manager. This was a left over from the early days when we were using JPA via Spring. We no longer do that, so I was not expecting Spring to break on Hibernate version update. On searching the bean definition, I found the incorrect reference to JPA/Hibernate and removed it. The application runs fine now.

Changed this:

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

To this:

<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource"></property>
</bean>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.