-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: No CurrentSessionContext configured!
PostPosted: Mon Nov 23, 2009 11:19 am 
Newbie

Joined: Thu Oct 29, 2009 2:59 am
Posts: 10
Hello,

ich have (in my opinion) a strange Exception, I start my web- Application (with TOMCAT) and it runs a few minutes or longer and after a while I get the Exception above and I don't know, what's the problem,
Thanks a lot for help,

All the best,
Generic1


Code:
23.11.2009 16:08:49 org.apache.catalina.core.StandardContext reload
INFO: Reloading this Context has started
23.11.2009 16:08:49 org.springframework.context.support.AbstractApplicationContext doClose
INFO: Closing org.springframework.web.context.support.XmlWebApplicationContext@16f0be8: display name [Root WebApplicationContext]; startup date [Mon Nov 23 16:07:38 CET 2009]; root of context hierarchy
23.11.2009 16:08:49 org.springframework.beans.factory.support.DefaultSingletonBeanRegistry destroySingletons
INFO: Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@d507e9: defining beans [org.springframework.context.annotation.internalPersistenceAnnotationProcessor,org.springframework.context.annotation.
internalCommonAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.
springframework.context.annotation.internalRequiredAnnotationProcessor,xmlElementProvider,reader,startdatabase,
starttcp,trendservice,_delegatingMethodDefinitionSource,_accessManager,_methodSecurityInterceptor,_methodSecurityInterceptorPostProcessor,_methodDefinitionSourceAdvisor,org.springframework.aop.config.internalAutoProxyCreator,
_authenticationManager,_filterChainProxy,_httpSessionContextIntegrationFilter,_filterChainProxyPostProcessor,_filterChainList,_securityContextHolderAwareRequestFilter,_portMapper,_exceptionTranslationFilter,_channelProcessingFilter,_channelDecisionManager,
_filterSecurityInterceptor,_sessionFixationProtectionFilter,_anonymousAuthenticationProvider,_anonymousProcessingFilter,_rememberMeServices,_rememberMeAuthenticationProvider,_rememberMeFilter,_rememberMeServicesInjectionBeanPostProcessor,_logoutFilter,_basicAuthenticationEntryPoint,_basicAuthenticationFilter,_formLoginFilter,_formLoginEntryPoint,_entryPointInjectionBeanPostProcessor,_userServiceInjectionPostProcessor,org.springframework.security.providers.dao.DaoAuthenticationProvider#0,
org.springframework.security.userdetails.memory.InMemoryDaoImpl#0,org.springframework.security.config.AuthenticationProviderBeanDefinitionParser$AuthenticationProviderCacheResolver#0]; root of factory hierarchy
Exception in thread "Timer-0" org.hibernate.HibernateException: No CurrentSessionContext configured!
        at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:620)
        at net.hibernate.BasicManager.getSession(BasicManager.java:29)
        at net.hibernate.EventManager.storeTrendVariable(EventManager.java:55)
        at net.hibernate.DatabaseInterface.createAndStoreTrendVariable(DatabaseInterface.java:59)
        at net..hibernate.StartDatabase.createAndStoreTrendVariable(StartDatabase.java:200)
        at net.trend.TrendWriteTimerTask.writeCurrentValueInDatabase(TrendWriteTimerTask.java:30)
        at net.trend.TrendWriteTimerTask.run(TrendWriteTimerTask.java:22)
        at java.util.TimerThread.mainLoop(Timer.java:512)
        at java.util.TimerThread.run(Timer.java:462)
Exception in thread "receiveDataThread" org.hibernate.HibernateException: No CurrentSessionContext configured!


Here is the class, where I get the Exception:

Code:
package net.ppos.hibernate;

import java.sql.Timestamp;
import java.util.List;
import org.hibernate.Session;
import org.hibernate.SessionFactory;

public abstract class BasicManager {

    private SessionFactory factory = null;
    private boolean transactionHandled;

    protected BasicManager() {}

    protected void ensureTransaction() {
        if (transactionHandled) {
            getSession().getTransaction().commit();
       transactionHandled = false;
            }
        else if (!getSession().getTransaction().isActive()) {
            getSession().beginTransaction();
            transactionHandled = true;
            }
        }

    public synchronized Session getSession() {                                   
        if (factory == null)
            factory = InitSessionFactory.getInstance();
        return factory.getCurrentSession();     // here is the problem
        }



And here is my config- file:

Code:
<hibernate-configuration>
  <session-factory>
    <property name="connection.driver_class">driver ...</property>
    <property name="connection.url">url ...</property>
    <property name="connection.username">User</property>
    <property name="connection.password">Pass ...</property>
    <property name="connection.pool_size">1</property>
    <!-- JDBC connection pool (use the built-in) -->
    <property name="dialect">dialect ...</property>
    <!-- SQL dialect -->
    <property name="current_session_context_class">org.hibernate.context.ThreadLocalSessionContext</property>
    <property name="transaction.auto_close_session">true</property>
    <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
    <!-- Disable the second-level cache  -->
    <property name="show_sql">false</property>
    <!-- Echo all executed SQL to stdout -->
    <property name="hbm2ddl.auto">create</property>
    <!-- Drop and re-create the database schema on startup -->
    <property name="c3p0.max_size">5</property>
    <property name="c3p0.max_size">2</property>
    <!-- mapping to the entity- config- classes  -->
   <mapping resource="..."/>
    <mapping resource="..."/>
    <mapping resource="..."/>
   <mapping resource="..."/>
   <mapping resource="..."/>
  </session-factory>
</hibernate-configuration>


Top
 Profile  
 
 Post subject: Re: No CurrentSessionContext configured!
PostPosted: Mon Nov 23, 2009 4:24 pm 
Regular
Regular

Joined: Mon Aug 07, 2006 5:07 am
Posts: 56
I'm not sure but it might be the auto_close_session property or the current_session_context_class property.

I use this Configuration, and during unit tests I don't experience any problems with it.
Code:
<session-factory>
      <property name="hibernate.connection.driver_class">...</property>
      <property name="hibernate.connection.url">...</property>
      <property name="hibernate.connection.username">...</property>
      <property name="hibernate.connection.password">...</property>
      <property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>
      <!-- JDBC connection pool (use the built-in) -->
      <property name="connection.pool_size">1</property>
      <!-- Enable Hibernate's automatic session context management -->
      [b]<property name="current_session_context_class">thread</property>[/b]
      <!-- Disable the second-level cache -->
      <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
      <!-- Echo all executed SQL to stdout -->
      <property name="show_sql">false</property>
      <!-- Validate the database schema on startup -->
      <property name="hbm2ddl.auto">validate</property>
...

Please do check out and let me know if it solved anything.


Top
 Profile  
 
 Post subject: Re: No CurrentSessionContext configured!
PostPosted: Tue Nov 24, 2009 3:49 am 
Newbie

Joined: Thu Oct 29, 2009 2:59 am
Posts: 10
Hello,

first thanks for the response,
I have tried this out before (with thread) but it doesn't change anything, Maybe the problem I have is related with an other exception. Sometimes I get the exception at the bottom, when I start my application,
So the excepion is a Nullpointerexception and appears at this line:

Code:
static {
            final Configuration cfg = new Configuration();
            cfg.configure("/hibernate.cfg.xml");
            final String sessionFactoryJndiName = cfg.getProperty(Environment.SESSION_FACTORY_NAME);
            try {
                if (sessionFactoryJndiName != null) {
                    cfg.buildSessionFactory();
                    sessionFactory = (SessionFactory) (new InitialContext()).lookup(sessionFactoryJndiName);
                    }
                else {
                    sessionFactory = cfg.buildSessionFactory();   // here the exception appears
                    }
                }
            catch (NamingException e) {
                throw new HibernateException("Could not configure Hibernate configuration", e);
                }
        }


DO you know why this happenes?
Thanks a lot,
All the best,
Generic1

Code:
Exception in thread "Thread-1" java.lang.ExceptionInInitializerError
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
        at java.lang.Class.newInstance0(Class.java:355)
        at java.lang.Class.newInstance(Class.java:308)
        at org.hibernate.cfg.SettingsFactory.createQueryTranslatorFactory(SettingsFactory.java:399)
        at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:240)
        at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2119)
        at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2115)
        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1339)
        at nethibernate.InitSessionFactory.<clinit>(InitSessionFactory.java:24)
        at net.hibernate.BasicManager.getSession(BasicManager.java:28)
        at net.hibernate.EventManager.storeVariable(EventManager.java:20)
        at net.hibernate.DatabaseInterface.createAndStoreVariable(DatabaseInterface.java:27)
        at net.hibernate.StartDatabase.insertVariables(StartDatabase.java:41)
        at netservice.StartService.<init>(StartService.java:19)
        at net.contextlistener.ContextListener$1.run(ContextListener.java:25)
Caused by: java.lang.NullPointerException
        at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:243)
        at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:255)
        at org.hibernate.hql.ast.ASTQueryTranslatorFactory.<clinit>(ASTQueryTranslatorFactory.java:44)
        ... 18 more



Top
 Profile  
 
 Post subject: Re: No CurrentSessionContext configured!
PostPosted: Tue Nov 24, 2009 8:50 am 
Regular
Regular

Joined: Mon Aug 07, 2006 5:07 am
Posts: 56
Do you have the slf4j-api.jar and slf4j-log4j12.jar in your classpath?

For example, I'm using Maven.
When I have a dependency to hibernate-core-3.5.2-Beta2 it automatically downloads a dependency to slf4j-api-1.5.8.jar.
You manually need to download the Log4J implementation of SLF4J if you are using Log4J (or commons logging if you use thatone...) AND it has to be the correct version for the version of the SLF4J-API.
Code:
<dependency>
   <groupId>org.slf4j</groupId>
   <artifactId>slf4j-log4j12</artifactId>
   <version>1.5.8</version>
   <scope>runtime</scope>
</dependency>


If it is the wrong version for the slf4j-api.jar you are having, then you might get NullPointers, NoSucMethodErrors or InitializationExceptions.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.