-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4243025
By: grzegorzk__
Assume we have two domain classes: Resource and CmsType and Resource contains reference to CmsType:
---
Resource res = new Resource();
CmsType type = new CmsType();
res.setCmsType(type);
---
res.cmsType is 'lazy' so we need open session to read it.
In zul page there's a listbox that displays list of available resources and CmsType's name of resources (with livedata).
But when: res.getCmsType().getName() [in renderer] it throws exception
'org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed' -
So what could I do to prevent session from closing? (in this case 'org.springframework.orm.hibernate3.support.OpenSessionInViewFilter' doesn't
work)
One of solutions is to read resource again from Database in renderer but it will reduce performance.
----------------
--- list.zul ---
<?xml version="1.0" encoding="UTF-8"?>
<zk
xmlns="http://www.zkoss.org/2005/zul"
xmlns:h="http://www.w3.org/1999/xhtml"
xmlns:zk="http://www.zkoss.org/2005/zk"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.zkoss.org/2005/zul
http://www.zkoss.org/2005/zul/zul.xsd">
<zscript>
<![CDATA[
import com.edirect.pl.app.cms.zk.livedata.CmsLiveData;
model = CmsLiveData.getTestListModel();
renderer = CmsLiveData.getTestListItemRenderer();
]]>
</zscript>
<listbox model="${model}" itemRenderer="${renderer}"/>
</zk>
------------------------
--- CmsLiveData.java ---
package com.edirect.pl.app.cms.zk.livedata;
class CmsLiveData
{
@SuppressWarnings( "unchecked" )
public static ListModelList getTestListModel()
{
ICMS cmsFacade = (ICMS)SpringUtil.getBean("cms");
List list =
cmsFacade.getResourceManager().getResources(CmsUtil.getWebsiteId());
return new ListModelList(list);
}
public static ListitemRenderer getTestListItemRenderer()
{
return new ListitemRenderer()
{
public void render( Listitem item, Object data ) throws Exception
{
Resource res = (Resource)data;
item.setAttribute("item",res,Component.COMPONENT_SCOPE);
Listcell cell = new Listcell(res.getName());
cell.setParent(item);
Listcell cell = new Listcell(res.getCmsType().getName());
cell.setParent(item);
}
};
}
}
---------------
--- web.xml ---
....
<filter>
<filter-name>hibernateFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilt
er</filter-class>
</filter>
<filter-mapping>
<filter-name>hibernateFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
....
Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4243166
By: jumperchen
Try to use Hibernate.initialize method.
You can refer to the following message.
http://www.javalobby.org/java/forums/t20533.html
Jumper
Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4244414
By: grzegorzk__
Hi
I don't want to initializes all lazy associations in object (eg object may have collections with 1000000 big objects). I'm searching for something like OpenSessionInView to get lazy associations when I need them.
Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4246374
By: henrichen
Did you have these lines in WEB-INF/zk.xml ?
<listener>
<description>Spring TransactionSynchronizationManager handler</description> <listener-class>
org.zkoss.zkplus.spring.SpringTransactionSynchronizationListener
</listener-class>
</listener>
/henri
Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4256511
By: grzegorzk__
Hi Henri
YES, I have this lines in zk.xml
Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4258230
By: henrichen
It has something to do with how you access your persistent objects.
1. load the zul page: HttpRequest, Hiberate Session1 (hb1) open, the
CmsLiveData.getTestListModel() method loads all "resources" and all resources object now associated with Hibernate Session1 (hb1). Then the hb1 is closed automatically by "OpenSessionInView" filter.
2. user drag the scrollbar. XMLHttpRequest (Ajax Request), Hibernate Session2
(hb2) open, the renderer attempt to lazy load name from the "resource" object that was loaded in another Hibernate Session1 (hb1). The Hibernate engine try to use the hb1 (since it is the Hibernate session that loaded the resource object) and complain it (hb1) is already closed.
To solve this issue, you have to "reattach" the resource object to "current"
Hibernate session (hb2) before doing the lazy load. try
session.lock(res, LockMode.NONE);
/henri
Asked: 2007-04-04 10:34:23 +0800
Seen: 304 times
Last updated: Apr 13 '07