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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:26:46+00:00 2026-05-24T16:26:46+00:00

I refactored my service layer to work as generic component. After that all request

  • 0

I refactored my service layer to work as generic component. After that all request to my controller began to throw org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here.

I searched over the internet and found common reasons:

  1. Lack of @Transaction annotation.
  2. Usage of hibernate.current_session_context_class and hibernate.transaction_factory_class options.
  3. Direct calls to sessionFactory.openSession().
  4. Using BeanFactory instead of ApplicationContext.
  5. Several instances of DAO class.

But it seems that none of them are related to my case.

I would appreciate any help as I’ve spent all my day with this exception.

Stacktrace

[INFO] 2011-08-12 15:42:49,383 [btpool0-0] INFO  ru.centr_in.rescuer.server.web.InfoJournalController - FETCH started: all
[INFO] 2011-08-12 15:42:49,383 [btpool0-0] DEBUG org.springframework.orm.hibernate3.SessionFactoryUtils - Opening Hibernate Session
[INFO] 2011-08-12 15:42:49,383 [btpool0-0] DEBUG org.hibernate.impl.SessionImpl - opened session at timestamp: 13131493693
[INFO] 2011-08-12 15:42:49,383 [btpool0-0] DEBUG org.springframework.orm.hibernate3.SessionFactoryUtils - Closing Hibernate Session
[INFO] 2011-08-12 15:42:49,383 [btpool0-0] DEBUG org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerExceptionResolver - Resolving exception from handler [ru.centr_in.rescuer.server.web.InfoJournalController@14e1b74]: org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
[INFO] 2011-08-12 15:42:49,384 [btpool0-0] DEBUG org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver - Resolving exception from handler [ru.centr_in.rescuer.server.web.InfoJournalController@14e1b74]: org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
[INFO] 2011-08-12 15:42:49,384 [btpool0-0] DEBUG org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver - Resolving exception from handler [ru.centr_in.rescuer.server.web.InfoJournalController@14e1b74]: org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
[INFO] 2011-08-12 15:42:49,384 [btpool0-0] DEBUG org.springframework.web.servlet.DispatcherServlet - Could not complete request
[INFO] org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
[INFO]  at org.springframework.orm.hibernate3.SpringSessionContext.currentSession(SpringSessionContext.java:63)
[INFO]  at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:574)
[INFO]  at ru.centr_in.rescuer.server.dao.HibernateGenericDao.findAll(HibernateGenericDao.java:41)
[INFO]  at ru.centr_in.rescuer.server.service.AbstractCRUDServiceBean.findAll(AbstractCRUDServiceBean.java:21)
[INFO]  at ru.centr_in.rescuer.server.web.InfoJournalController.getInfoJournalEntries(InfoJournalController.java:40)
[INFO]  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[INFO]  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[INFO]  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[INFO]  at java.lang.reflect.Method.invoke(Method.java:597)
[INFO]  at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)
[INFO]  at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:426)
[INFO]  at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:414)
[INFO]  at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790)
[INFO]  at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
[INFO]  at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
[INFO]  at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549)
[INFO]  at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
[INFO]  at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
[INFO]  at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
[INFO]  at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362)
[INFO]  at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
[INFO]  at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
[INFO]  at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:729)
[INFO]  at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
[INFO]  at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
[INFO]  at org.mortbay.jetty.handler.RequestLogHandler.handle(RequestLogHandler.java:49)
[INFO]  at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
[INFO]  at org.mortbay.jetty.Server.handle(Server.java:324)
[INFO]  at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
[INFO]  at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:829)
[INFO]  at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:513)
[INFO]  at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
[INFO]  at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
[INFO]  at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
[INFO]  at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488)

Controller

@Controller
public class InfoJournalController {

    @Autowired
    private InfoJournalService infoJournalService;

    @RequestMapping(value="/infoJournal", method=RequestMethod.GET)
    public @ResponseBody InfoJournalEntry[] getInfoJournalEntries() {

        List<InfoJournalEntry> entries = infoJournalService.findAll();
        InfoJournalEntry[] result = new InfoJournalEntry[entries.size()];
        entries.toArray(result);
        return result;
    }
} 

Generic service interface

public interface AbstractCRUDService<E, PK extends Serializable> {
    void save(E entity);
    List<E> findAll();
    E findById(PK id);
    void delete(E entity);
    void update(E entity);
} 

Generic service implementation

@Transactional
public abstract class AbstractCRUDServiceBean<E, PK extends Serializable> implements   AbstractCRUDService<E, PK> {

    //....

    @Transactional
    public List<E> findAll() {
        return getDao().findAll();
    }

    //....

    public abstract AbstractDao<E, PK> getDao();
}

Concrete service interface

public interface InfoJournalService extends AbstractCRUDService<InfoJournalEntry, Long>     }

Concrete service implementation

@Service("infoJournalService")
public class InfoJournalServiceImpl extends AbstractCRUDServiceBean<InfoJournalEntry, Long> implements InfoJournalService {

    @Autowired
    private InfoJournalDao infoJournalDao;

    @Override
    public AbstractDao<InfoJournalEntry, Long> getDao() {
        return infoJournalDao;
    }
}

Generic DAO interface

public abstract class HibernateGenericDao<E, PK extends Serializable> implements AbstractDao<E, PK> {

    @Autowired
    protected SessionFactory sessionFactory;

    //....

    @SuppressWarnings("unchecked")
    public List<E> findAll() {
        return sessionFactory.getCurrentSession().createCriteria(getEntityClass()).list();
    }

    public abstract Class getEntityClass();
}

Generic DAO implementation
public abstract class HibernateGenericDao implements AbstractDao {

    @Autowired
    protected SessionFactory sessionFactory;

    //....

    @SuppressWarnings("unchecked")
    public List<E> findAll() {
        return sessionFactory.getCurrentSession().createCriteria(getEntityClass()).list();
    }

    public abstract Class getEntityClass();
}

Concrete DAO implementation

@Repository("infoJournalDao")
public class InfoJournalDaoImpl extends HibernateGenericDao<InfoJournalEntry, Long>     implements InfoJournalDao {

    @Override
    public Class getEntityClass() {
        return InfoJournalEntry.class;
    }
}

root-context.xml

  <context:annotation-config />
  <context:component-scan base-package="ru.centr_in.rescuer.server" />
  <import resource="datasource.xml" />

datasource.xml

 <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager" >
  <property name="sessionFactory" ref="sessionFactory" />
 </bean>

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

 <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
  <property name="location">
    <value>WEB-INF/database.properties</value>
  </property>
 </bean>

 <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
  <property name="driverClassName" value="${jdbc.driverClassName}" />
  <property name="url" value="${jdbc.url}"/>
  <property name="username" value="${jdbc.username}"/>
  <property name="password" value="${jdbc.password}"/>
 </bean>

 <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
   <property name="dataSource" ref="dataSource"/>
   <property name="configurationClass">
     <value>org.hibernate.cfg.AnnotationConfiguration</value>
   </property>
   <property name="hibernateProperties">
     <props>
       <prop key="hibernate.show_sql">true</prop>
       <prop key="hibernate.hbm2ddl.auto">create</prop> 
       <prop key="hibernate.dialect">${jdbc.dialect}</prop>
       <prop key="hibernate.connection.charset">UTF-8</prop>
     </props>
   </property>

   <property name="annotatedClasses">
        <list>
            <value>ru.centr_in.rescuer.server.domain.InfoJournalEntry</value>
        </list>
   </property>
 </bean>

servlet-context.xml

 <annotation-driven/>
 <context:component-scan base-package="ru.centr_in.rescuer.server" />

 <resources mapping="/resources/**" location="/resources/"/>
 <resources mapping="/Rescuer.html" location="/Rescuer.html"/>
 <resources mapping="/Rescuer/**" location="/Rescuer/"/>

 <beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <beans:property name="prefix" value="/WEB-INF/views/"/>
    <beans:property name="suffix" value=".jsp"/>
 </beans:bean>
  • 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-24T16:26:47+00:00Added an answer on May 24, 2026 at 4:26 pm

    It seems I’ve found my mistake.
    Both root-context.xml and servlet-context.xml contain the same line <context:component-scan base-package="ru.centr_in.rescuer.server" />.

    Now I specified base packages in the following way:

    root-context.xml

    <context:component-scan base-package="ru.centr_in.rescuer.server.service" />
    <context:component-scan base-package="ru.centr_in.rescuer.server.dao" />
    

    and servlet-context.xml

    <context:component-scan base-package="ru.centr_in.rescuer.server.web" />
    

    And now everything works.

    Thanks to Miles from Entities Not Persisting – Spring + Hibernate + JPA

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

Sidebar

Related Questions

I just refactored some code that was in a different section of the class
A little background: I'm using Spring and Hibernate to create a really simple domain/dao/service
1) What are the BLL-services ? What's the difference between them and Service Layer
In the bank I work all client workstations have .Net 2 installed it is
There is no surprise for those who work with web-services a lot that they
We are looking at reworking a java business management web service that has been
I have an application that is an asmx web service written in .NET 2.0
I have an MVC3 app with a simple Log service. All my services are
I have one module written on Java - web service module which accepts request
I'm in a position where our company has a database search service that is

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.