Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7660419
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:27:48+00:00 2026-05-31T13:27:48+00:00

I work with Spring 3.1 + Hibernate 4. I’ve created the following sessionFactory :

  • 0

I work with Spring 3.1 + Hibernate 4.

I’ve created the following sessionFactory:

<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <property name="dataSource" ref="myDataSource" />
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
            <prop key="hibernate.show_sql">true</prop>
            <prop key="hibernate.hbm2ddl.auto">validate</prop>
        </props>
    </property>
    <property name="packagesToScan" value="com.my.company"/>
</bean>

As you see, the above sessionFactory is for Hibernate 4.

I am trying to crate a HibernateTemplate (org.springframework.orm.hibernate3.HibernateTemplate) through Java code, by that sessionFactory, but I am not sure how to do this.

I’ve tried the following code:

@Resource(name="sessionFactory")
public void setSessionFactory(LocalSessionFactoryBean sessionFactory) {
    this.hibernateTemplate = new HibernateTemplate(sessionFactory.getObject());
}

But I’m getting the following error message:

org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'sessionFactory' must be of type [org.springframework.orm.hibernate4.LocalSessionFactoryBean], but was actually of type [org.hibernate.internal.SessionFactoryImpl]

Could you show how to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T13:27:48+00:00Added an answer on May 31, 2026 at 1:27 pm

    As from this post:

    HibernateTemplate isn’t recommended for use anymore (about since the
    release of hibernate 3.0.1) there is no more added value so that isn’t
    going to be in there anymore for hibernate 4. Simply use the plain
    SessionFactory and use the getCurrentSession method to obtain the
    current transactional session (don’t use openSession!!!!) and you are
    good to go…

    From the javadoc of package org.springframework.orm.hibernate4:

    Contains an implementation of Spring’s transaction SPI for local
    Hibernate transactions. This package is intentionally rather minimal,
    with no template classes or the like, in order to follow native
    Hibernate recommendations as closely as possible.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I work on Spring MVC + Hibernate application, use MySQL (ver. 5.0.51a) with the
when using hibernate with spring, can someone explain how the session unit of work
I work with Spring/Hibernate Dao's for saving my Object in the Database. Now I
I've been using the following web development stack for a few years: java/spring/hibernate/mysql/jetty/wicket/jquery For
I am deploying my application to Tomcat 6.0.20. Application uses Hibernate as ORM, Spring,
I'm working on an hibernate Spring Mysql app, sometimes when i make a gethibernateTemplate()get(class,id)
How properly lifecycle of a Hibernate session under Spring should be done? The SessionFactory
I work on an legacy application, where Spring AOP (namely ProxyFactoryBean ) is used.
I'm wondering why the following code doesn't work: String test = new String(new byte[]
Consider the code: class Work { public void DoStuff(string s) { Console.WriteLine(s); // ..

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.