0

ZK + Hibernate: saveOrUpdate is not valid without active transaction - error

asked 2008-09-18 08:27:00 +0800

deuter gravatar image deuter
15 1 1 1

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"?

delete flag offensive retag edit

3 Replies

Sort by ยป oldest newest

answered 2008-09-18 10:39:01 +0800

robbiecheng gravatar image robbiecheng
1144 2
http://robbiecheng.sys-co...

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

link publish delete flag offensive edit

answered 2008-09-18 12:01:57 +0800

deuter gravatar image deuter
15 1 1 1

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

link publish delete flag offensive edit

answered 2008-09-18 14:49:54 +0800

henrichen gravatar image henrichen
3869 2
ZK Team

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.

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2008-09-18 08:27:00 +0800

Seen: 1,325 times

Last updated: Sep 18 '08

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More