-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: LazyInitializationException
PostPosted: Fri Oct 29, 2010 11:18 pm 
Newbie

Joined: Tue Oct 19, 2010 5:00 am
Posts: 2
Dear all,

I encountered LazyInitializationException today in my SSH project today as follows.

Code:
>>>>>>>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.

Code:
        <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.

Code:
>>>>>>>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 actually an ajax action and the result is in json format ready to be passed back.

Code:
<package name="ajax" namespace="/" extends="json-default">
                ...
                <action name="getInfoByCustomer" class="ajaxGetInfoByCustomer">
                        <result type="json" />
                </action>
                ...
        </package>


Could anyone kindly to glance it?

Terry.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.