-->
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.  [ 6 posts ] 
Author Message
 Post subject: Exception: No CurrentSessionContext configured!
PostPosted: Tue Apr 25, 2006 5:31 pm 
Beginner
Beginner

Joined: Thu Apr 20, 2006 11:51 am
Posts: 44
Hibernate version: last
Hello I'm using Eclipse, Hibernate and Jboss (all the last ver.)

Now I get a new exception " No CurrentSessionContext configured!"
I've these classes
---HIBERNATESERVLET--
public class HibernateServlet extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {

public HibernateServlet() {
super();
}


protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("CIAO");

ToolStudente ts = new ToolStudente();

List studenti = ts.listaStudenti();


for (int i=0; i < studenti.size(); i++){
Studenti thestudent = (Studenti) studenti.get(i);
System.out.println("Studente: " + thestudent.getCognome() + thestudent.getNome()
+ " matricola: "+ thestudent.getMatricola());
}
}

---TOOL STUDENTE--
public class ToolStudente {

public List listaStudenti () {

Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
List result = session.createQuery("from Studenti").list();
session.getTransaction().commit();

return result;

}

}

--HIBERNATE UTIL--
public class HibernateUtil {

private static final SessionFactory sessionFactory;
static {
try {
// Create the SessionFactory from hibernate.cfg.xml
sessionFactory = new Configuration().configure().buildSessionFactory();
} catch (Throwable ex) {
// Make sure you log the exception, as it might be swallowed
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}

public static SessionFactory getSessionFactory() {
return sessionFactory;
}

}


The hibernate tool plugin works well.
When I try to do a List of Student from my servlet (''List studenti = ts.listaStudenti();'')
the exception is generated when the app. call Configuration().configure().buildSessionFactory()

JBOSS gives me this error (I try wiith tomcat5.5 is the same)
---
21:31:23,390 ERROR [[HibernateServlet]] Servlet.service() for servlet HibernateServlet threw exception
org.hibernate.HibernateException: No CurrentSessionContext configured!
at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:506)
at com.hibernate.servlet.ToolStudente.listaStudenti(ToolStudente.java:26)
at com.hibernate.servlet.HibernateServlet.service(HibernateServlet.java:29)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:159)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
at java.lang.Thread.run(Thread.java:595)
---

Someone can help me?
thx alain


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 25, 2006 6:36 pm 
Expert
Expert

Joined: Tue Dec 07, 2004 6:57 am
Posts: 285
Location: Nürnberg, Germany
In your hibernate.properties / hibernate.cfg.xml you need to set the property hibernate.current_session_context_class to either jta or thread.

_________________
Please don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 26, 2006 11:49 am 
Beginner
Beginner

Joined: Thu Apr 20, 2006 11:51 am
Posts: 44
Yes. but now one more time I've the other problem Exception

with this
--
sessionFactory = new Configuration().configure("hibernateJNCV.cfg.xml").buildSessionFactory();
--
tomcat say
--
Initial SessionFactory creation failed. java.lang.NoClassDefFoundError: net/sf/ehcache/CacheException

with this
--
sessionFactory = new Configuration().configure("hibernate_xml/hibernateJNCV.cfg.xml").buildSessionFactory();
--
tomcat say
--
Initial SessionFactory creation failed. org.hibernate.HibernateException: hibernate_xml/hibernateJNCV.cfg.xml not found


I use eclipse, here there's a screenshot of my webapp
http://i3.tinypic.com/wipkpf.gif

I try to add the 'hibernate_xml' in the classpath with this steps
Properties->java Build Path->Add Folder->hibernate_xml

now I've my 'hibernate_xml' folder that contains all the xml for configuration&mapping under the JavaSource (src).

Why Hibernate can't see hibernateJNCV.cfg.xml when I call the Configuration.configure(...) ??!

xcuse me 4 the stupid question..I'm a newbie
thx to all
;)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 26, 2006 12:13 pm 
Beginner
Beginner

Joined: Thu Apr 20, 2006 11:51 am
Posts: 44
the error was that I've not imported the
ehcache-1.1.jar !

I've resolved also the other problem of No CurrentSessionContext configured!

I've added the
<!-- session properties -->
<property name="hibernate.current_session_context_class">org.hibernate.context.ThreadLocalSessionContext</property>
as you say
now it works!
Thanks a lot!


Top
 Profile  
 
 Post subject: Re: Exception: No CurrentSessionContext configured!
PostPosted: Fri Feb 19, 2010 1:22 am 
Newbie

Joined: Sun Jan 31, 2010 8:27 pm
Posts: 2
Hi...you can forget the hibernate.cfg.xml if you copy the file in your source package or ...if you used the orm library, you can copy the ormmapping folder (with hibernate file) outside of the package src..
Thanks mike for the property line!!!!


Top
 Profile  
 
 Post subject: Re: Exception: No CurrentSessionContext configured!
PostPosted: Mon May 13, 2013 1:31 am 
Newbie

Joined: Mon May 13, 2013 1:29 am
Posts: 1
Fine After adding
<property name="hibernate.current_session_context_class">org.hibernate.context.ThreadLocalSessionContext</property>
this my problem also solved
thanks log


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