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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:12:00+00:00 2026-06-04T23:12:00+00:00

Using Hibernate 4 and Spring 3.1. Just getting up and running with it so

  • 0

Using Hibernate 4 and Spring 3.1. Just getting up and running with it so this may be a lack of understanding on my part. I have a method in a Service class which calls a method in a DAO class to retrieve some data using Hibernate. I annotate the Service method with @Transactional but get an error when calling getCurrentSession in the DAO method. If I annotate the DAO method with @Transactional as well then the data is successfully retrieved. I don’t understand why though – I would have thought that the @Transactional annotation on the Service method would have created a Hibernate session, bound it to the thread and that this session would be returned in the DAO class when getCurrentSession is called. Can anyone explain why this is the case or if I am doing something wrong, thanks?

root-context.xml:

<tx:annotation-driven transaction-manager="transactionManager"/>

Service class:

public class BlahServiceImpl implements BlahService {

    @Transactional  
    public Blah GetMostRecentBlah() {
        BlahDAO blahDAO = DAOFactory.GetBlahDAO();
        return blahDAO.GetMostRecentBlah();
    }
}

DAO class:

private SessionFactory sessionFactory;

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

public Blah GetMostRecentBlah() {
    return (Blah)sessionFactory.getCurrentSession().createQuery("from Blah where blahID = (select max(blahID) from Blah)").uniqueResult();
}

Error:

org.hibernate.HibernateException: No Session found for current thread
org.springframework.orm.hibernate4.SpringSessionContext.currentSession(SpringSessionContext.java:97)
org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:1039)
com.blah.blah.DAO.BlahDAOImpl.GetMostRecentBlah(BlahDAOImpl.java:18)

Like I said, if I annotate the DAO function with @Transactioanl (as well as the Service method) this works but I don’t understand why.

  • 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-06-04T23:12:02+00:00Added an answer on June 4, 2026 at 11:12 pm

    Two probable causes suggest themselves.

    1) Your service bean is in a separate ApplicationContext, which doesn’t have annotation-driven transactions enabled.

    2) You’re obtaining a reference to an instance of your service that’s the raw instance instead of a proxied, and therefore transactional, instance.

    To determine which is your problem, or determine if it’s some other problem, show the context file that causes your service bean to be created, and show the code where you’re getting an instance of your service.

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

Sidebar

Related Questions

I'm using Hibernate 3.6.7-Final and Spring 3.0.5. I have entity like this @Entity public
I'm trying to combine Spring with Hibernate using Annotations and I'm getting the following
Implementing a simple Login screen using JSF and Spring and Hibernate. I have written
I have a project with spring and hibernate in GWT, I am using below
A little background: I'm using Spring and Hibernate to create a really simple domain/dao/service
I'm trying to persist a very simple class using Hibernate. I'm not using Spring,
I am using Hibernate in Spring MVC 3.05 and an Oracle database. I have
How could I integrate Spring with Hibernate using sql server 2005 and have Unicode
I have an application which are using Hibernate / Spring and Spring MVC, but
I have java application with web interface (Spring MVC) using Hibernate. I have quite

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.