Announcement Announcement Module
No announcement yet.
No HibernateDaoSupport for hibernate4 Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • No HibernateDaoSupport for hibernate4

    Am attempting to upgrade from Spring 3.0.5.RELEASE to 3.2.0.RELEASE. Am also upgrading Hibernate to 4.1.9.Final.

    The SpringFramework has updated hibernate4 support classes such as SessionFactoryUtils. However, there is no hibernate4 version of HibernateDaoSupport. Also, hibernate3.HibernateDaoSupport uses hibernate3.SessionFactoryUtils.

    So in trying to obtain a Session, I'm seeing this error:

    Caused by: java.lang.NoSuchMethodError: org.hibernate.SessionFactory.openSession()Lorg/hibernate/classic/Session;
    at org.springframework.orm.hibernate3.SessionFactoryU tils.doGetSession(
    at org.springframework.orm.hibernate3.SessionFactoryU tils.getSession(
    at teDaoSupport.getSession( 68)
    I think the error is because Hibernate 4.1's SessionFactory's openSession() does not return an org.hibernate.classic.Session; it returns an org.hibernate.Session.

    We're using the hibernate4.LocalSessionFactoryBean as the factory for the SessionFactory

    Honestly, I'm not 100% sure what is causing this problem, but I will say that in opening the hibernate3.SessionFactoryUtils class, I do see all kinds of errors because the Hibernate 4.x API is different from the Hibernate 3.x.

    I'm thinking what is needed is a org.springframework.orm.hibernate4.HibernateDaoSup port that uses other Spring hibernate4.* references instead of the hibernate3.* references.

    Any thoughts?

    Last edited by madjack; Dec 20th, 2012, 02:56 PM.

  • #2
    You shouldn't be using HibernateDaoSupport (or HIbernateTemplate) those should be considered deprecated as of Hibernate 3.0.1 (which was released around 2006/2007).

    Simply inject a sessionfactory and call the getCurrentSession method on the sessionfactory to obtain a session, you could put this in an abstract class of your own if you want a convenience method.