[hibernate-issues] [Hibernate-JIRA] Updated: (HHH-2728) Calling session.clear() while retrieving objects via an iterator will cause a "LazyInitializationException - No Session" by the CGLIBLazyInitializer

Gail Badner (JIRA) noreply at atlassian.com
Tue Jul 17 02:54:52 EDT 2007


     [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-2728?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Gail Badner updated HHH-2728:
-----------------------------

    Attachment: HHH-2728-testcase.patch

I have verified that this bug was introduced by the fix for HHH-511, which changed StatefulPersistenceContext.clear() to set the session field in proxies to null when Session.clear() is called.

The problem is that org.hibernate.impl.IteratorImpl.next() calls IteratorImpl.postNext(), which creates a proxy to be returned the next time IteratorImpl.next()  is called. At the time the proxy is created, the session field is properly set. After clearing the session, the session field in the proxy is set to null.

I have also verified that Query.iterate() works properly when entities are evicted while iterating (instead of clearing the session).

I am attaching a patch against core/branches/Branch_3_2 for two tests added to org.hibernate.test.reattachment.ProxyReattachmentTest that reproduce the bug and the workaround.

> Calling session.clear() while retrieving objects via an iterator will cause a "LazyInitializationException - No Session" by the CGLIBLazyInitializer
> ----------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: HHH-2728
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2728
>             Project: Hibernate3
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 3.2.4.sp1
>         Environment: Any
>            Reporter: Metin Göktay
>            Priority: Minor
>         Attachments: HHH-2728-testcase.patch
>
>
> Given the following code 
>             Iterator stagingIterator = query.iterate("from "+entityName+" where importSourceFile.id = ?", deliveryId);  // large result set 
>             while (stagingIterator.hasNext()) {
>                 Importable staging = stagingIterator.next();
>                 Approvable approvable = this.approve(staging);
>                 tmp.add(approvable);
>                 i++;
>                 if (i % 200 == 0) {
>                     LOG.debug("Flushing+Clearing after "+i+" entries.");
>                     session.flush();
>                     session.clear();
>                 }
>             }
> After clearing the session for the first time (resp. after the first 200 entries) the CGLIBInitializer object of next returned HibernateProxy object does not have a session any longer resulting in a "LazyInitializationException - No Session" exception.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       




More information about the hibernate-issues mailing list