Spring Framework
  1. Spring Framework
  2. SPR-9365

Doc: Spring 3.x and Hibernate 4 are not compatible. Unable to use HibernateTemplate.

    Details

    • Type: Task Task
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Complete
    • Affects Version/s: None
    • Fix Version/s: 3.1.4, 3.2.1
    • Component/s: None
    • Labels:
      None
    • Last commented by a User:
      false

      Description

      While using Spring HibernateTemplate with the combination of Spring 3.1 and Hibernate 4, we are getting the following exception.

      java.lang.ClassCastException: org.springframework.orm.hibernate4.SessionHolder cannot be cast to org.springframework.orm.hibernate3.SessionHolder
      	at org.springframework.orm.hibernate3.SessionFactoryUtils.doGetSession(SessionFactoryUtils.java:287)
      	at org.springframework.orm.hibernate3.SessionFactoryUtils.getSession(SessionFactoryUtils.java:233)
      	at org.springframework.orm.hibernate3.HibernateTemplate.getSession(HibernateTemplate.java:457)
      	at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:393)
      	at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
      	at org.springframework.orm.hibernate3.HibernateTemplate.loadAll(HibernateTemplate.java:584)
      

        Issue Links

          Activity

          Hide
          Bilguun Bayarmagnai added a comment -

          I think spring hibernateTemplates are no longer supported with hibernate 4. Use plain sessionFactory instead

          Show
          Bilguun Bayarmagnai added a comment - I think spring hibernateTemplates are no longer supported with hibernate 4. Use plain sessionFactory instead
          Hide
          Oliver Gierke added a comment -

          HibernateTemplate is not supposed to be used with Hibernate 4 as it resides in the hibernate3 package. So if you want to upgrade to Hibernate 4 use the Hibernate API directly.

          Show
          Oliver Gierke added a comment - HibernateTemplate is not supposed to be used with Hibernate 4 as it resides in the hibernate3 package. So if you want to upgrade to Hibernate 4 use the Hibernate API directly.
          Hide
          Augustine Parthinathan added a comment -

          If Spring3.1 HibernateTemplate has been designed not to support Hibernate 4, then it should throw an appropriate error message in the exception. But, we are getting a ClassCastException.

          Also the javadoc for the package org.springframework.orm.hibernate4 does not give any clue that HibernateTemplate is no longer supported. Please refer following URL http://static.springsource.org/spring/docs/3.1.x/javadoc-api/org/springframework/orm/hibernate4/package-summary.html.

          It should either be a defect or this information should be included in the documentation or javadoc.

          Show
          Augustine Parthinathan added a comment - If Spring3.1 HibernateTemplate has been designed not to support Hibernate 4, then it should throw an appropriate error message in the exception. But, we are getting a ClassCastException. Also the javadoc for the package org.springframework.orm.hibernate4 does not give any clue that HibernateTemplate is no longer supported. Please refer following URL http://static.springsource.org/spring/docs/3.1.x/javadoc-api/org/springframework/orm/hibernate4/package-summary.html . It should either be a defect or this information should be included in the documentation or javadoc.
          Hide
          Oliver Gierke added a comment -

          Re-assigning to Jürgen for further review.

          Show
          Oliver Gierke added a comment - Re-assigning to Jürgen for further review.
          Hide
          Juergen Hoeller added a comment -

          Added corresponding hint to hibernate4 package summary.

          Note that the Hibernate3 version of HibernateTemplate isn't even aware of the existence of Hibernate4; it just expects the right Hibernate version to be there. Those hibernateX support packages are completely independent, after all.

          Juergen

          Show
          Juergen Hoeller added a comment - Added corresponding hint to hibernate4 package summary. Note that the Hibernate3 version of HibernateTemplate isn't even aware of the existence of Hibernate4; it just expects the right Hibernate version to be there. Those hibernateX support packages are completely independent, after all. Juergen

            People

            • Assignee:
              Juergen Hoeller
              Reporter:
              Augustine Parthinathan
              Last updater:
              Juergen Hoeller
            • Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since last comment:
                1 year, 13 weeks, 5 days ago