Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate: No CurrentSessionContext configured

I keep getting a :

HibernateException: No CurrentSessionContext configured!

in my code. The only information other searches that returned is that the culprit is:

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

in my hibernate.cfg.xml. I do have that in my hibernate.cfg.xml file, and I am running this in Tomcat 6. Does anyone know other possible causes?

like image 429
jconlin Avatar asked Apr 17 '09 17:04

jconlin


People also ask

What is the use of Hibernate Current_session_context_class?

hibernate. context. CurrentSessionContext ) and a new configuration parameter ( hibernate. current_session_context_class ) have been added to allow pluggability of the scope and context of defining current sessions.

What is the difference between openSession and getCurrentSession?

openSession() always opens a new session that you have to close once you are done with the operations. SessionFactory. getCurrentSession() returns a session bound to a context - you don't need to close this.

What is Session factory in hibernate?

SessionFactory is an Interface which is present in org. hibernate package and it is used to create Session Object. It is immutable and thread-safe in nature.


1 Answers

I believe you need to set your current_session_context_class to an actual class...I have my hibernate.cfg.xml configured for that as follows:

<property name="hibernate.current_session_context_class">org.hibernate.context.ThreadLocalSessionContext</property> 

The above code is used for a mySql database but i don't think it matters what type the database is for the above property

Hope this helps

like image 155
Ian Dallas Avatar answered Sep 28 '22 04:09

Ian Dallas