org.hibernate.HibernateException: No CurrentSessionContext configured!

Spring JIRA | Erwin Vervaet | 9 years ago
tip
Your exception is missing from the Samebug knowledge base.
Here are the best solutions we found on the Internet.
Click on the to mark the helpful solution and get rewards for you help.
  1. 0

    Setting the exposeTransactionAwareSessionFactory property on a Hibernate 3 LocationSessionFactoryBean to false will break transactional tests. Is this expected? It made me scratch my head for a while so I thought I'd report it. For instance, the following config: <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource" ref="..." /> <property name="exposeTransactionAwareSessionFactory" value="false"/> <property name="hibernateProperties"> <props>...</props> </property> <property name="mappingDirectoryLocations" ref="..." /> <property name="mappingLocations" ref="..."/> </bean> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> Will cause this test to fail: @ContextConfiguration(locations = { "classpath:beans.xml" }) public class TestNGTest extends AbstractTransactionalTestNGSpringContextTests { @Autowired private SessionFactory sessionFactory; @Test public void testStuff() { sessionFactory.getCurrentSession().flush(); } } The same is true if you rewrite the test using classing JUnit: public class JUnitTest extends AbstractTransactionalSpringContextTests { private SessionFactory sessionFactory; protected String[] getConfigLocations() { return new String[] { "classpath:beans.xml" }; } public void setSessionFactory(SessionFactory sessionFactory) { this.sessionFactory = sessionFactory; } @Test public void testStuff() { sessionFactory.getCurrentSession().flush(); } } The error you get is: org.hibernate.HibernateException: No CurrentSessionContext configured! at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:542) at foo.bar.TestNGTest.testStuff(TestNGTest.java:19) at org.springframework.test.context.testng.AbstractTestNGSpringContextTests.run(AbstractTestNGSpringContextTests.java:146)

    Spring JIRA | 9 years ago | Erwin Vervaet
    org.hibernate.HibernateException: No CurrentSessionContext configured!
  2. 0

    Setting the exposeTransactionAwareSessionFactory property on a Hibernate 3 LocationSessionFactoryBean to false will break transactional tests. Is this expected? It made me scratch my head for a while so I thought I'd report it. For instance, the following config: <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource" ref="..." /> <property name="exposeTransactionAwareSessionFactory" value="false"/> <property name="hibernateProperties"> <props>...</props> </property> <property name="mappingDirectoryLocations" ref="..." /> <property name="mappingLocations" ref="..."/> </bean> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> Will cause this test to fail: @ContextConfiguration(locations = { "classpath:beans.xml" }) public class TestNGTest extends AbstractTransactionalTestNGSpringContextTests { @Autowired private SessionFactory sessionFactory; @Test public void testStuff() { sessionFactory.getCurrentSession().flush(); } } The same is true if you rewrite the test using classing JUnit: public class JUnitTest extends AbstractTransactionalSpringContextTests { private SessionFactory sessionFactory; protected String[] getConfigLocations() { return new String[] { "classpath:beans.xml" }; } public void setSessionFactory(SessionFactory sessionFactory) { this.sessionFactory = sessionFactory; } @Test public void testStuff() { sessionFactory.getCurrentSession().flush(); } } The error you get is: org.hibernate.HibernateException: No CurrentSessionContext configured! at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:542) at foo.bar.TestNGTest.testStuff(TestNGTest.java:19) at org.springframework.test.context.testng.AbstractTestNGSpringContextTests.run(AbstractTestNGSpringContextTests.java:146)

    Spring JIRA | 9 years ago | Erwin Vervaet
    org.hibernate.HibernateException: No CurrentSessionContext configured!
  3. Speed up your debug routine!

    Automated exception search integrated into your IDE

  4. 0

    hibernate JNDI error

    Stack Overflow | 6 years ago | zeusakm
    org.hibernate.HibernateException: No CurrentSessionContext configured!
  5. 0

    Hibernate "No CurrenetSessionContext "Error

    Stack Overflow | 5 years ago | EdgeCase
    org.hibernate.HibernateException: No CurrentSessionContext configured!

    2 unregistered visitors
    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. org.hibernate.HibernateException

      No CurrentSessionContext configured!

      at org.hibernate.impl.SessionFactoryImpl.getCurrentSession()
    2. Hibernate
      SessionFactoryImpl.getCurrentSession
      1. org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:542)
      1 frame
    3. foo.bar
      TestNGTest.testStuff
      1. foo.bar.TestNGTest.testStuff(TestNGTest.java:19)
      1 frame
    4. Spring TestContext
      AbstractTestNGSpringContextTests.run
      1. org.springframework.test.context.testng.AbstractTestNGSpringContextTests.run(AbstractTestNGSpringContextTests.java:146)
      1 frame