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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:14:59+00:00 2026-05-29T11:14:59+00:00

I am using Hibernate3 with Spring 3. I am trying to start hibernate transaction

  • 0

I am using Hibernate3 with Spring 3. I am trying to start hibernate transaction using Spring.
Given below is my configurations

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="configLocation" value="classpath:hibernate.cfg.xml" />
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />

I am getting the following error while running the application.

HibernateException: get is not valid without active transaction
    at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:341)

I have the following line in hibernate config xml

<property name="hibernate.current_session_context_class">thread</property>

The code which uses hibernate transaction is:

SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
Session session = sessionFactory.getCurrentSession();
Book book = (Book)session.get(Book.class, id);

What could be wrong in this? Is the value for current_session_context_class is anything other than thread?

  • 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-29T11:15:00+00:00Added an answer on May 29, 2026 at 11:15 am

    The problem was in the line

    SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();

    It seems, When you are using Spring transaction management, you need to use the sessionFactory which you configured in the applicationContext.xml (using dependency injection).

    Following piece of code solved the problem.

    private SessionFactory sessionFactory;
    public void setSessionFactory(SessionFactory sessionFactory)
    {
       this.sessionFactory = sessionFactory;
    }
    

    In the applicationContext.xml:

    <bean id="BookService" class="hibernate.BookServiceImpl">
       <property name="sessionFactory" ref="sessionFactory" />
    </bean>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to persist a very simple class using Hibernate. I'm not using Spring,
I'm trying to setup Spring using Hibernate and JPA, but when trying to persist
I'm trying to combine Spring with Hibernate using Annotations and I'm getting the following
I'm using Spring with Hibernate as a JPA provider and are trying to get
I'm using hibernate validator framework with Spring. A class implementing the Spring Validator validates
Using Hibernate 3.6.8.Final and Spring 3.0.5.RELEASE , I'm trying to add some Common DAO
I'm trying to execute a simple stored procedure with Spring/Hibernate using Annotations. Here are
I am trying to develop a web project using Hibernate 4 and spring 3.1.
I'm trying to make a project using struts 2, spring 3 and hibernate, but
I have Roo-generated Spring MVC application connected to PostgreSQL using Hibernate. I am trying

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.