-
FEATURED COMPONENTS
First time here? Check out the FAQ!
In "longer" transactions within my webapp I non-regularly get this error message.
Somehow the transaction seems to vanish.
I'm working with a SessionFactory (with save) and transaction (begin, commit) as described in "Java Persistence in Hibernate" book.
I already use the listener ....
<listener>
<description>Hibernate thread session context handler</description>
<listener-class>org.zkoss.zkplus.hibernate.HibernateSessionContextListener
</listener-class>
</listener>
... in config file of hibernate. But this didn't solve the problem.
I've read about using a Transaction Manager and not
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
... but this seems to be pretty heavy stuff.
Can you give me advice or hints how to get the transactions "safe"?
Try to add opensessioninview listener in zk.xml, as follows,
<listener>
<description>Hibernate "Open Session In View" Session Lifecycle</description>
<listener-class>org.zkoss.zkplus.hibernate.OpenSessionInViewListener</listener-class>
</listener>
/robbie
Hi, thanks for answer from one of the masters...
I did this already,
got
javax.servlet.ServletException: Servlet execution threw an exception
java.lang.ExceptionInInitializerError
org.zkoss.zkplus.hibernate.HibernateUtil.initSessionFactory(HibernateUtil.java:133)
org.zkoss.zkplus.hibernate.HibernateUtil.initSessionFactory(HibernateUtil.java:116)
org.zkoss.zkplus.hibernate.HibernateUtil.getSessionFactory(HibernateUtil.java:68)
org.zkoss.zkplus.hibernate.HibernateUtil.currentSession(HibernateUtil.java:75)
org.zkoss.zkplus.hibernate.OpenSessionInViewListener.init(OpenSessionInViewListener.java:54)
org.zkoss.zk.ui.util.Configuration.invokeExecutionInits(Configuration.java:796)
org.zkoss.zk.ui.impl.UiEngineImpl.execNewPage0(UiEngineImpl.java:312)
org.zkoss.zk.ui.impl.UiEngineImpl.execNewPage(UiEngineImpl.java:276)
org.zkoss.zk.ui.http.DHtmlLayoutServlet.process(DHtmlLayoutServlet.java:227)
org.zkoss.zk.ui.http.DHtmlLayoutServlet.doGet(DHtmlLayoutServlet.java:167)
javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
In Hibernate+ZK article by Henri it is written, that a servlet filter can be used instead of this listener. Is there something active, which I have to deactivate?
Or did I miss something from the article?
btw. I use Hibernate 3.25 and ZK 3.0.6. Will upgrade asap, but not very frequently during development.
br,
martin
Let's do some experiment first.
In file WEB-INF/zk.xml add following lines.
<system-config> <disable-event-thread/> </system-config>
This tells ZK not to spawn a new event thread and thus we can eliminate the ThreadLocal issue. What the OpenSessionInViewListener did is to open transaction in the beginning of a http request and close transaction at the end of the http request. If you still encounter issues, it is better that you can provide some sample codes.
Asked: 2008-09-18 08:27:00 +0800
Seen: 1,325 times
Last updated: Sep 18 '08