-->
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: Hibernate Lazy initialization Exception
PostPosted: Fri Jun 23, 2006 3:22 am 
Newbie

Joined: Fri Jun 23, 2006 3:06 am
Posts: 1
Location: Nagpur, India
I am facing problem with Hibernate Lazy initialization.
I tried to make lazy=true in mapping file, to improve the performance of the site.
without turning it to true, entire object tree is getting loaded into memory.

Following are the steps I followed

1.
I made lazy=true for all classes, and the associations which each class possess.
-> I got LazyInitializationException: could not initialize proxy - the owning Session was closed
I started adding lazy to one class and it's associated classes. But problem was still there.

2.
Added OpenSessionInViewFilter as follows to resolve above exception.
<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>/*</url-pattern>
</filter-mapping>

3.
I started getting
-> HibernateSystemException: a different object with the same identifier value was already associated with the session: nested exception is org.hibernate.NonUniqueObjectException

4.
To resolve NonUniqueObjectException, I tried to catch it and started using merge() supported by hibernate 3.0 as follows.

try{
getHibernateTemplate().saveOrUpdate(o);
}
catch(HibernateSystemException hse){
getHibernateTemplate().merge(o);
}

5.
By doing all above steps I could resolve the problem only for few classes and relations.
If I try to enable lazy for others, I still get LazyInitializationException: could not initialize proxy - the owning Session was closed

This lazy problem has taken lot of efforts by now. I would appreciate if any one could suggest where I could be doing wrong.


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.