0

Spring + Hibernate + Zk

asked 2009-06-10 13:44:06 +0800

fabsoli gravatar image fabsoli
51

Hi again...

I´m using Spring + Hibernate + Zk and i had configure open session in view filter to use lazy mode... everythink work´s fine until i try to use fulfill property and get the lazy initialization exceptions again... anyone pass thru this issue?

tnx

delete flag offensive retag edit

8 Replies

Sort by » oldest newest

answered 2009-06-10 14:06:17 +0800

xenoky gravatar image xenoky
42

have you added this lines to zk.xml?
<listener>
<description>Hibernate thread session context handler</description>
<listener-class>
org.zkoss.zkplus.hibernate.HibernateSessionContextListener
</listener-class>
</listener>

for details read this small talk: http://www.zkoss.org/smalltalks/hibernatezk/hibernatezk.dsp

link publish delete flag offensive edit

answered 2009-06-10 15:38:05 +0800

fabsoli gravatar image fabsoli
51

this is my actual zk:

<?xml version="1.0" encoding="UTF-8"?>

<!--
Created by ZK Studio
-->

<zk>
<listener>
<description>ThreadLocal Synchronization Listener
</description>
<listener-class>org.zkoss.zkplus.util.ThreadLocalListener
</listener-class>
</listener>

<preference>
<name>ThreadLocal</name>
<value>
org.springframework.security.context.ThreadLocalSecurityContextHolderStrategy=contextHolder
</value>
</preference>

</zk>

and i tried like this:

<?xml version="1.0" encoding="UTF-8"?>

<!--
Created by ZK Studio
-->

<zk>
<listener>
<description>ThreadLocal Synchronization Listener
</description>
<listener-class>org.zkoss.zkplus.util.ThreadLocalListener
</listener-class>
</listener>

<preference>
<name>ThreadLocal</name>
<value>
org.springframework.security.context.ThreadLocalSecurityContextHolderStrategy=contextHolder
</value>
</preference>

<listener>
<description>Hibernate thread session context handler</description>
<listener-class>
org.zkoss.zkplus.hibernate.HibernateSessionContextListener
</listener-class>
</listener>


</zk>

and this....::
<?xml version="1.0" encoding="UTF-8"?>

<!--
Created by ZK Studio
-->

<zk>
<listener>
<description>Hibernate thread session context handler</description>
<listener-class>
org.zkoss.zkplus.hibernate.HibernateSessionContextListener
</listener-class>
</listener>
</zk>


and both didn´t work.... remembering... it stops to work just when i try with de fulfill property seted up...

<tabbox id="tabNota">
<tabs>
<tab label="Detalhe" id="tabDetalhe" />
<tab label="Lista" id="tabLista" />
<tab label="Relatório" onClick="imprime();"
id="labelRelatorio" visible="control.temNotasRelatorio()" />
</tabs>

<tabpanels>
.
.
.
.
.
<tabpanel fulfill="tabLista.onSelect">
.
.
.
.

link publish delete flag offensive edit

answered 2009-06-10 16:18:29 +0800

sousa1981 gravatar image sousa1981
573 4

I don't use anymore Open Session in view Mode, BTW, here is my zk.xml:

<zk>
	<!-- Optional -->
	<device-config>
		<device-type>ajax</device-type>
		<timeout-uri></timeout-uri>
		<!-- An empty URL can cause the browser to reload the same URL -->
	</device-config>
	
	<!-- Turn on if you want to ignore the consecutive click events,
	if it happens too close to the previous one, or the server is still
	serving the previous click.
	-->
	<client-config>
		<click-filter-delay>390</click-filter-delay>
	</client-config>
	
	<error-page>
		<exception-type>org.zkoss.zk.ui.UiException</exception-type>
		<location>/WEB-INF/sys/uiException.zul</location>
	</error-page>
	
	<preference>
		<name>org.zkoss.zul.Window.defaultActionOnShow
		</name>
		<value></value>
	</preference>
	
	<listener>
		<description>ThreadLocal varaibles synchronizer</description>

		<listener-class>
			org.zkoss.zkplus.util.ThreadLocalListener
		</listener-class>
	</listener>

	<preference>
		<name>ThreadLocal</name>
		<value>
			org.springframework.web.context.request.RequestContextHolder=requestAttributesHolder,inheritableRequestAttributesHolder;
			org.springframework.transaction.support.TransactionSynchronizationManager=resources,synchronizations,currentTransactionName,currentTransactionReadOnly,actualTransactionActive;
			org.springframework.orm.hibernate3.SessionFactoryUtils=deferredCloseHolder;
			org.springframework.transaction.interceptor.TransactionAspectSupport=transactionInfoHolder;
		</value>
	</preference>
</zk>

link publish delete flag offensive edit

answered 2009-06-10 17:13:54 +0800

fabsoli gravatar image fabsoli
51

the open session in view is on my web.xml....

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>Duralex Sistemas</display-name>

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value> <![CDATA[
classpath:applicationContext-core.xml
classpath:applicationContext-security.xml
/WEB-INF/applicationContext-web.xml
]]> </param-value>
</context-param>

<!-- FILTRO DO HIBERNATE (PERMITE O LAZY MODE) -->
<filter>
<filter-name>hibernateFilter</filter-name>
<filter-class>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
<init-param>
<param-name>singleSession</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>hibernateFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>


<!--
- Spring Security Filter Chains
-->
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>


<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<listener>
<description>
Used to cleanup when a session is destroyed</description>
<display-name>ZK Session Cleaner</display-name>
<listener-class>org.zkoss.zk.ui.http.HttpSessionListener</listener-class>
</listener>
<servlet>
<description>
The servlet loads the DSP pages.</description>
<servlet-name>dspLoader</servlet-name>
<servlet-class>org.zkoss.web.servlet.dsp.InterpreterServlet</servlet-class>
</servlet>
<servlet>
<description>
ZK loader for ZUML pages</description>
<servlet-name>zkLoader</servlet-name>
<servlet-class>org.zkoss.zk.ui.http.DHtmlLayoutServlet</servlet-class>
<init-param>
<param-name>update-uri</param-name>
<param-value>/zkau</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<description>
The asynchronous update engine for ZK</description>
<servlet-name>auEngine</servlet-name>
<servlet-class>org.zkoss.zk.au.http.DHtmlUpdateServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>dspLoader</servlet-name>
<url-pattern>*.dsp</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>zkLoader</servlet-name>
<url-pattern>*.zul</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>zkLoader</servlet-name>
<url-pattern>*.zhtml</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>auEngine</servlet-name>
<url-pattern>/zkau/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
<welcome-file>index.zul</welcome-file>
</welcome-file-list>
</web-app>


should i take it off?

link publish delete flag offensive edit

answered 2009-06-11 10:12:25 +0800

sousa1981 gravatar image sousa1981
573 4

fabsoli,

No, your web.xml looks ok and zk.xml together.

I think every thing is OK. You should stop use lazy. Use dedicated service which will call hibernate
Put "org.springframework.orm.hibernate3.support.OpenSessionInViewFilter" over LOGGER in DEBUG mode, to see connection opening and closing.

Acho que está tudo bem.
Voce deve parar de usar lazy load.
Deve usar services dedicados que fazem o job de call ao hibernate.
Deve usar load on demand também.
Coloca "org.springframework.orm.hibernate3.support.OpenSessionInViewFilter" em modo de DEBUG para ver a conexao a abrir e fechar.

link publish delete flag offensive edit

answered 2009-06-11 10:14:05 +0800

sousa1981 gravatar image sousa1981
573 4

Já que voce quer carregar objectos em lazy usa directamente na especificacao de collection o modo lazy, acho que carrega logo os objectos.

link publish delete flag offensive edit

answered 2009-06-11 11:46:58 +0800

edudant gravatar image edudant
219 1 1 1
zk.datalite.cz

updated 2009-06-11 11:49:31 +0800

English please :)

The OpenSessionInViewFilter helps only for one request - the persistence context is expanded over whole request. However in another request (i.e. your onFulfill, but it can be just onClick) when you try to lazy load data from entity object loaded in previous request, the session is closed and you got the exception.

On last page of this thread I tried to show several solutions to this problem, but I didn't solved it yet. We still use Toplink essentials as a provider, which opens new session on daemand.

JBoss Seam solves this problem as well, you can find more details at Seam documentation page

link publish delete flag offensive edit

answered 2009-06-11 15:03:19 +0800

sousa1981 gravatar image sousa1981
573 4

edudant,

Very good explanation.

I only use Dedicated Service in addition to GenericService (which cover 80% of case) to do all necessary job.

Put code that depends on OpenSessionInViewFilter is bad, since tomorrow if some thing change (The View or You want move the core to webservice), you will do a lot of work.

Regards

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: 2009-06-10 13:44:06 +0800

Seen: 877 times

Last updated: Jun 11 '09

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