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 6555455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:49:20+00:00 2026-05-25T12:49:20+00:00

I want to integrate hibernate with spring. spring 3 documentation says that you can

  • 0

I want to integrate hibernate with spring. spring 3 documentation says that you can access session via org.hiberate.SessionFactory’s getCurrentSession() and this should be prefered over hibernateDaoSupport approach.

But I want to know how can we get hold of org.hiberate.SessionFactory’s instance in the first place if we are using AnnotationSessionFactoryBean?
I have done the following bean declaration in applicationContext.xml:

       <bean id="annotationSessionFactoryBean" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
              <property name="dataSource" ref="dataSource"/>
              <property name="packagesToScan" value="com.mydomain"/>
              <property name="hibernateProperties">
                  <props>
                    <prop key="hibernate.connection.pool_size">10</prop>
                    <prop key="hibernate.connection.show_sql">true</prop>
                    <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                  </props>
            </property>     
    </bean>

DAO which is using the session:

    <bean id="hibernateUserProfileDAO" class="com.springheatmvn.Dao.impl.hibernate.HibernateUserProfileDAO">
        <property name="annotationSessionFactoryBean" ref="annotationSessionFactoryBean"/>
    </bean>

In my hibernateUserProfileDAO I would like to get the current session like this

    public class HibernateUserProfileDAO implements UserProfileDAO {
      private AnnotationSessionFactoryBean annotationSessionFactoryBean;

      public UserProfile getUserProfile() {
    Session session = annotationSessionFactoryBean.getCurrentSession();
      ....
      }

But I see that there is no public getCurrentSession() method in AnnotationFactoryBean. I found only protected getAnnotationSession() method but it is also on Abstract session factory class.

Can any one please tell me where am i going wrong?

  • 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-25T12:49:21+00:00Added an answer on May 25, 2026 at 12:49 pm

    AnnotationSessionFactoryBean is a factory that produces SessionFactory automatically (Spring handles in internally), so that you need to use it as follows:

    <bean id="sf" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">        
        ...
    </bean>    
    
    <bean id="hibernateUserProfileDAO" class="com.springheatmvn.Dao.impl.hibernate.HibernateUserProfileDAO">
         <property name="sf" ref="sf"/>
    </bean>
    

    .

    public class HibernateUserProfileDAO implements UserProfileDAO {
        private SessionFactory sf;    
        ...
    }
    

    Then you obtain a Session by calling sf.getCurrentSession().

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

Sidebar

Related Questions

I want to build an application using Hibernate and MyBatis integrate with Spring. In
I want to Integrate Spring and Hibernate and use JTA for managing the transactions.
I want to select the lastest frameworks to integrate spring, struts and hibernate, but
Long story below short question: How can I get Spring's NamedParameterJDBCTemplate join Hibernate's session?
i want to to integrate spring jsf hibernate. i use maven and eclipse. but
i want to integrate jsf2.0 and spring 3.1 and hibernate 4.1. but tomcat has
i want to integrate Struts with Hibernate. I am new to these technologies. Infortunately
I want to integrate facebook login into my web application developed using Spring MVC.
i want integrate admob ads to my palm pre application.can you please suggest me
We have a large existing website (written in Java/Spring/Hibernate/JSP) and want to add a

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.