본문 바로가기

Development/Web & Server

[Spring Framework] Hibernate 연동시... @Transitional 이 제대로 동작 안할때!!

No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional


위와 같은 에러가 뜬다면 많은 이유가 있겠지만 그 이유는 중 하나이다.


해결방법은 2가지가 있다.


첫번째 

         this.mSessionFactory.getCurrentSession()


위와 같이 쓰고 있다면


   this.mSessionFactory.openSession()


으로 바꾸어서 써라



두번째 방법

web.xml에서 아래의 코드를 추가해라


<filter>

<filter-name>HibernateSession</filter-name>

<filter-class>

org.springframework.orm.hibernate3.support.OpenSessionInViewFilter

</filter-class>

</filter>


<filter-mapping>

<filter-name>HibernateSession</filter-name>

<url-pattern>/*</url-pattern>

</filter-mapping>


이유는..

The reason behind this issue is hibernate session is not bound with HTTP request by deafult. You have to bind it. So whether you open it directly or use spring provided interceptor


하이버네이트의 경우 HTTP Reuest에 대해서는 기본적으로 Bound하지 않는다고 한다. 그래서 이것을 스프링이 처리할수 있도록 바인딩 하거나 직접 Open으로 처리를 하도록 해야한다.??


이 사항에 대해 자세히 보실려면..