-->
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.  [ 2 posts ] 
Author Message
 Post subject: No CurrentSessionContext configured Error
PostPosted: Sat Nov 26, 2011 11:22 am 
Newbie

Joined: Sat Nov 26, 2011 11:14 am
Posts: 3
I am getting the following error. I searched google. They are giving the answer to add the following element(in bold) for the error. I have added it to the hibernate.cfg.xml file. I am still getting the same error I pasted below.

<property name="current_session_context_class">thread</property>

Error Stack
Quote:
Step 1
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Step 2Exception in thread "main"
Sesssion Factory value org.hibernate.impl.SessionFactoryImpl@104c575
org.hibernate.HibernateException: No CurrentSessionContext configured!
at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:685)


Code
Code:
public class Main { 
     
    public static void main(String[] args)   
    { 
        System.out.println("Step 1"); 
        SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory(); 
        System.out.println("Step 2"); 
        System.out.println("Sesssion Factory value "+sessionFactory); 
        Session session = sessionFactory.getCurrentSession();  //Error is occuring at this line
                System.out.println("Step 3"); // This line is not being displayed


hibernate.cfg.xml
Code:
    <hibernate-configuration> 
    <session-factory> 
     
    <!-- hibernate dialect --> 
    <property name="hibernate.dialect">org.hibernate.dialect.ProgressDialect</property> 
    <property name="hibernate.connection.driver_class">org.postgresql.Driver</property> 
    <property name="hibernate.connection.url">jdbc:postgresql://127.0.0.1:5432/testdb</property> 
    <property name="hibernate.connection.username">postgres</property> 
    <property name="hibernate.connection.password">venkat7</property> 
    <property name="hibernate.connection.pool_size">1</property> 
    <property name="current_session_context_class">thread</property> 
    <mapping resource="com/sample/Person.hbm.xml"/> 
     
    </session-factory> 
    </hibernate-configuration> 


Top
 Profile  
 
 Post subject: Re: No CurrentSessionContext configured Error
PostPosted: Sat Nov 26, 2011 12:32 pm 
Newbie

Joined: Sat Nov 26, 2011 11:14 am
Posts: 3
My issue got resolved the change I have done is as follows

Session session = sessionFactory.getCurrentSession(); //Earlier I was using

Session session = sessionFactory.openSession(); //I changed the above line to this as shown

Now it is working fine.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.