Dear all, I encountered LazyInitializationException today in my SSH project today as follows.
>>>>>>>LOG4J<<<<<<< 1 2010-10-29 17:37:42,454 [http-8080-2] ERROR org.hibernate.LazyInitializationException - #org.hibernate.LazyInitializationException.<init>(LazyInitializationException.java:19)# - failed to lazily initialize a collection of role: model.Customer.people, no session or session was closed org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: model.Customer.people, no session or session was closed at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:358) at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:350) at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:343) at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86) at org.hibernate.collection.PersistentBag.iterator(PersistentBag.java:249) at org.apache.struts2.json.JSONWriter.process(JSONWriter.java:155) at org.apache.struts2.json.JSONWriter.value(JSONWriter.java:131) at org.apache.struts2.json.JSONWriter.add(JSONWriter.java:329) at org.apache.struts2.json.JSONWriter.bean(JSONWriter.java:228) at org.apache.struts2.json.JSONWriter.process(JSONWriter.java:165) at org.apache.struts2.json.JSONWriter.value(JSONWriter.java:131) at org.apache.struts2.json.JSONWriter.add(JSONWriter.java:329) at org.apache.struts2.json.JSONWriter.bean(JSONWriter.java:228) ... I had searched online and found that someone suggested to use OpenSessionInViewFilter in web.xml like the following. However, it had no effect to me and the same error still happened. <filter> <filter-name>hibernateFilter</filter-name> <filter-class> org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class> </filter> <filter-mapping> <filter-name>hibernateFilter</filter-name> <url-pattern>*.action</url-pattern> </filter-mapping> And someone suggested to set "lazy" to be true for many-to-one items in hibernate xml. However, after modifying the code another error happened as below. >>>>>>>LOG4J<<<<<<< 2 2010-10-29 17:46:59,907 [http-8080-2] ERROR org.hibernate.LazyInitializationException - #org.hibernate.LazyInitializationException.<init>(LazyInitializationException.java:19)# - could not initialize proxy - no Session org.hibernate.LazyInitializationException: could not initialize proxy - no Session at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:57) at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:111) at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.invoke(CGLIBLazyInitializer.java:150) at model.Customer$$EnhancerByCGLIB$$4d304287.getAddress(<generated>) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:616) at org.apache.struts2.json.JSONWriter.bean(JSONWriter.java:227) at org.apache.struts2.json.JSONWriter.process(JSONWriter.java:165) at org.apache.struts2.json.JSONWriter.value(JSONWriter.java:131) at org.apache.struts2.json.JSONWriter.add(JSONWriter.java:329) ... It is an ajax action and the result is in json format to be passed back. <package name="ajax" namespace="/" extends="json-default"> ... <action name="getInfoByCustomer" class="ajaxGetInfoByCustomer"> <result type="json" /> </action> ... </package> I attached here the action file and model files and also hibernate xmls. http://old.nabble.com/file/p30084356/GetInfoByCustomer.java GetInfoByCustomer.java http://old.nabble.com/file/p30084356/customer.person.hbm.xml customer.person.hbm.xml http://old.nabble.com/file/p30084356/Warehouse.java Warehouse.java http://old.nabble.com/file/p30084356/CustomerPerson.java CustomerPerson.java http://old.nabble.com/file/p30084356/Warehouse.java Warehouse.java Could anyone kindly to glance it? Terry. -- View this message in context: http://old.nabble.com/LazyInitializationException-tp30084356p30084356.html Sent from the Struts - User mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org