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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:55:30+00:00 2026-05-27T23:55:30+00:00

Hi I have the following problem when running junit test. org.hibernate.HibernateException: No Session found

  • 0

Hi I have the following problem when running junit test.

org.hibernate.HibernateException: No Session found for current thread
at org.springframework.orm.hibernate4.SpringSessionContext.currentSession(SpringSessionContext.java:97)
at org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:881)
at com.user.dao.UserDaoHibernateImpl.getUserByName(UserDaoHibernateImpl.java:40)
at com.user.service.UserServiceImpl.getUserName(UserServiceImpl.java:67)

My version:

hibernate 4.0.0 CR7
spring 3.1 CR2
wicket 1.5.3

@TransactionConfiguration(transactionManager = "test.transactionManager")
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:applicationContext-test.xml"})
public class AccountPageTestCase extends AbstractTransactionalJUnit4SpringContextTests 
{
          private WicketTester                tester;
          @Test
          public void signInUserMustGoToAccountPage() {
          this.tester.startPage(AccountPage.class, new PageParameters());

          final FormTester formTester =   this.tester.newFormTester(AuthenticatedTestApplication.SIGN_IN_FORM_PATH);
          formTester.setValue("username", AccountPageTestCase.TEST_USER);
          formTester.setValue("password", AccountPageTestCase.TEST_USER);
          formTester.setValue("rememberMeRow:rememberMe", false);
          formTester.submit();

          this.tester.assertRenderedPage(AccountPage.class);

          this.tester.clickLink("accountBody:" +  AuthenticatedTestApplication.SIGN_OUT_PANEL_PATH);
        }
    }

I added tx:annotation-driven in here.

<tx:annotation-driven transaction-manager="test.transactionManager" />
<bean id="test.transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager"
autowire="byType" />

So my getUserByName code

@Override
@Transactional(propagation = Propagation.SUPPORTS,
           readOnly = true)
public User getUserByName(final String displayName) {
    return this.userDao.getUserByName(displayName);
}

My accountpage constructor.

@SpringBean(name = "userService")
private transient UserService userService;

public AccountPage(final PageParameters pageParameters) {
        final String userName = pageParameters.get("name").toString(StringUtils.EMPTY);
        final User user = this.userService.getUserByName(userName);
}

the injection works but the transaction settings doesn’t seem to work.

What is wrong? what would be the best way to solve the problem. I prefer not to use hibernate template and keep a non invasive hibernate approach.

My spring+hibernate test doesn’t have the no session found for current thread but if i use wicket tester i get the problem.

  • 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-27T23:55:31+00:00Added an answer on May 27, 2026 at 11:55 pm

    Hi i found the solution.

    I decided to stimulate open session in view in my test.

    public void TestApp extends AuthenticatedWebApplication  {
         @Override 
         public void init() {
           // open session in view for testing.
            final SessionFactory sessionFactory = AuthenticatedTestApplication.context.getBean("sessionFactory", SessionFactory.class);
            final Session s = sessionFactory.openSession();
            TransactionSynchronizationManager.bindResource(sessionFactory, new SessionHolder(s));
         }
    
         @Override
         protected void onDestroy() {
            super.onDestroy();
            final SessionFactory sessionFactory = AuthenticatedTestApplication.context.getBean("sessionFactory", SessionFactory.class);
            final SessionHolder sessionHolder = (SessionHolder) TransactionSynchronizationManager.unbindResource(sessionFactory);
            SessionFactoryUtils.closeSession(sessionHolder.getSession());
         }
    }
    

    so this will be use for application in testing.

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

Sidebar

Related Questions

I have the following problem: I have a form in site/banen (currently local running
Has anyone encountered the following problem: I have IIS7 running on my computer. On
I am using JUnit 4.10 for running test suites, and I have implemented a
I have a problem running my android project through eclipse. It gives following error
I'm running a small Zen-Cart shop and I have the following problem. When I'm
We have the following problem while running the git fsck --full --strict command: error:
Trying to get ActiveMQ with JNDI running following ( http://activemq.apache.org/jndi-support.html ) and i have
I'm running with the following problem. I have a few Managed Beans that are
So i'm running lampp on ubuntu 11.10 and i have the following problem i
I have following problem: I have built a tabbar application with 4 tabs. I

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.