Calling session.clear() while retrieving objects via an iterator will cause a "LazyInitializationException - No Session" by the CGLIBLazyInitializer

Description

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.

Environment

Any

Activity

Show:
Tom Eicher
November 23, 2007, 6:08 PM

This bug still appears in 3.2.5.ga.
The evict() workaround helps.

Gail Badner
November 26, 2007, 9:11 PM

Damien, which dialect are you using? When you run the unit tests on your 3.2 build using your dialect, do all the ProxyReattachmentTest tests succeed with your dialect?

DamienD
November 27, 2007, 9:53 PM

Gail,

I'll get back to you on this next week. I'm at a conference/trade show this week.

Thanks,
– Damien

Matan
March 3, 2008, 2:22 PM

I just noticed this fix in the 3.2.6ga release notes because I have the same problem with scroll() instead of iterate(). Is it possible there as well?

Matan
March 3, 2008, 3:51 PM

ignore the previous post.... the problem was in another layer...

Assignee

Gail Badner

Reporter

Metin Göktay

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Minor
Configure