我正在使用java命令行應用程序測試hibernate 4.1.9。我已經配置了當前會話的上下文線程:hibernate - getCurrentSession - 無活動事務無效
<property name="hibernate.current_session_context_class">thread</property>
但是,當我調用sessionFactory.getCurrentSession()
它拋出一個異常:
Exception in thread "main" org.hibernate.HibernateException: get is not valid without active transaction
at org.hibernate.context.internal.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:348)
at com.sun.proxy.$Proxy9.get(Unknown Source)
....
我可以用openSession
,它不會真正的問題(這是一個畢竟測試)。我只是好奇,爲什麼我不能讓方法getCurrentSession
像廣告一樣工作。
謝謝。
你確定這解決了該問題? – hop 2013-03-05 19:42:56
我不認爲這是解決這個問題的方法。 – lephix 2013-06-19 15:18:51
我只是試過這個,它不能解決問題 – catrapture 2013-07-19 04:50:10