If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > JAVA > Hibernate Lazy initialization Exception

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-23-06, 03:39
bhanucd bhanucd is offline
Registered User
 
Join Date: Jun 2006
Posts: 1
Hibernate Lazy initialization Exception

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.OpenSes sionInViewFilter
</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.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On