0

Hibernate, Spring, Sessions and Threads

asked 2006-08-22 13:48:08 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3879090

By: hlellelid

Hi,

I am very new to ZK, and am working on integrating an existing Spring+Hibernate framework with the ZK UI. I have read the Small Talk and HOWTO related to integrating Hibernate + ZK (+Spring), but haven't yet been able to answer this question for myself.

The problem I am encountering is that in our application the Hibernate Session that is being bound to the thread by an OpenSessionInViewFilter object is not available to all of the ZK processes that serve that request. (At least, this is my analysis so far.) I'm assuming that this is because ZK handles events in separate threads, so the onCreate() event for a ZK component might be part of the same request, but won't have access to that Filter-bound Hibernate Session.

What I'm wondering is where is the correct/best place to store these "per-request"
objects like the Hibernate Session. All threads that handle a single request need access to that object, but clearly it cannot be shared with threads that are handling other requests. Is this something that the Execution interface was designed to address?

Thanks in advance -
Hans

delete flag offensive retag edit

2 Replies

Sort by ยป oldest newest

answered 2006-08-24 02:12:04 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3882033

By: henrichen

Yes, event is handled in seperate thread.
As for per-request object, you can store and retrieve it with
Execution.setAttribute() and Execution.getAttribute().

http://zk1.sourceforge.net/javadoc/2.1.0/zk/com/potix/zk/ui/Execution.html#setAt
tribute(java.lang.String,%20java.lang.Object)

You can get current Execution with static methods Executions.getCurrent()



link publish delete flag offensive edit

answered 2006-09-22 14:05:47 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3928193

By: henrichen

Since ZK version 2006/9/21 Freshly. Please add following listener in your application's WEB-INF/zk.xml and you can use Spring's OpenSessionInViewFilter(or
Interceptor) as usual.

It bridge the ThreadLocal resources to event thread automatically so now the ThreadLocal pattern should works.

<listener>
<description>Spring TransactionSynchronizationManager handler</description> <listener-class>org.zkoss.zkplus.spring.SpringTransactionSynchronizationListene
r</listener-class>
</listener>


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: 2006-08-22 13:48:08 +0800

Seen: 351 times

Last updated: Sep 20 '21

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