---
title: "org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transac"
author: "hellostory"
date: "2011-02-12T14:38:00Z"
tags: []
slug: "org-hibernate-hibernateexception-no-hibernate-session-bound-to-thread-and-configuration-does-not-allow-creation-of-non-transac"
draft: false
lastmod: "2012-02-22T11:13:28Z"
id: 1416485
url: "https://hellostory.iteye.com/blog/1416485"
---

first of all if you want to use getcurrentSession() method you need to add these properties to HibernateProperties:  
**&lt;prop key="hibernate.current\_session\_context\_class"&gt;thread&lt;/prop&gt;**  
**&lt;prop key="hibernate.transaction.factory\_class"&gt;org.hibernate.transaction.JDBCTransactionFactory&lt;/prop&gt;**

添加后如下：

second thing is from the exception, Hibernate3 doesn't allow you to run queries without starting a transaction. you have to add this to your init method before running the query:  
sessionFactory.getCurrentSession().beginTransactio n();  
and of course commit it in the end of your unit of work.