-->
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: problem with Session sess = HibernateUtil.getSessionFactory
PostPosted: Tue Apr 19, 2011 3:02 am 
Newbie

Joined: Wed Mar 23, 2011 2:47 am
Posts: 8
hi to all,

I am facing a problem to open a session with

Session sess = HibernateUtil.getSessionFactory().getCurrentSession();(by using HibernateUtil.getSessionFactory().opensession() i get but i need with getcurrentsession() )

it shows error like

Exception in thread "main" org.hibernate.SessionException: Session was already closed
at org.hibernate.impl.SessionImpl.close(SessionImpl.java:302)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:342)
at $Proxy0.close(Unknown Source)
at com.srmri.model.studentmodel.setPatentScore(studentmodel.java:1453)
at com.srmri.model.studentmodel.setResearchScore(studentmodel.java:1060)
at com.srmri.model.studentmodel.main(studentmodel.java:118)


please help me if any body knows.

Thanks
krishna


Top
 Profile  
 
 Post subject: Re: problem with Session sess = HibernateUtil.getSessionFactory
PostPosted: Tue Apr 19, 2011 3:13 am 
Beginner
Beginner

Joined: Mon Apr 04, 2011 3:31 am
Posts: 41
Hi

try This Way

package com.voiceid.vopenidauth.hibernate;



import org.hibernate.HibernateException;

import org.hibernate.Session;

import org.hibernate.SessionFactory;

import org.hibernate.cfg.Configuration;



public class HibernateUtil

{

private static org.hibernate.SessionFactory sessionFactory;



public static SessionFactory getSessionFactory()

{

if (sessionFactory == null)

{

initSessionFactory();

}

return sessionFactory;

}



private static synchronized void initSessionFactory()

{

try

{

sessionFactory = new Configuration().configure().buildSessionFactory();

}

catch(HibernateException e)

{

e.printStackTrace();

}

}



public static Session getSession()

{

return getSessionFactory().getCurrentSession();

}

}

_________________
Thanks
Niki


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.