StatefulPersistenceContext.clear() does not clear nonlazyCollections

Description

During a query, an exception "collection is not associated with any session" from the doQueryAndInitializeNonLazyCollections. The problem is intermittent. Using a debugger I found that StatefulPersistenceContext was getting longer and longer with each query. The clear() method on StatefulPersistenceContext does not clear this field. I am wondering if clear() should call initializeTransientState().

Attachments

1

Activity

Show:

Brett Meyer December 1, 2014 at 10:17 PM

Closing – no test case nor response.

Former user August 14, 2014 at 7:26 PM

Hibernate should clean up nonLazyCollections when a Query is executed. There is something about your collection that causes this to not happen. Simply clearing it from the session avoids dealing with the bug.

I need to know details about the collection that remains in nonLazyCollections. If you cannot provide the mappng for the collection, I will assume that this is a duplicate of HHH-2862.

RobertB August 14, 2014 at 7:18 PM

Due to time constraints I am not going to be able to set this up again to reproduce it but here's what I saw in the debugger.

Every time a query ran on the session the length of nonlazy collections increased by 1. It contained something like a history of all of the non-lazy collections that session had loaded. At the time when the failure occurred, it has length 104. The time when it failed it was running a query on model object A, which joins to B and C. It went back to the start of non-lazy collections and tried to load all of them starting from 0. The one it failed on was a collection from P that associated to Q, nothing to do with A B or C. P and Q were earlyi in the 104 collections.

I patched the Hibernate source to clear() the nonlazy collections, used that in my test cases and the problem went away.

Former user August 14, 2014 at 6:57 PM

I suspect the association uses a join column that references a non-unique column.

It would really help if you could provide some details about the association.

RobertB August 14, 2014 at 4:56 PM

As far as I could tell using the debugger, the assocation it was trying to load was not associated to the object that loaded in the query. The assocation belonged to another object entirely than the one that was part of the query. It looked to me like it was trying to load an association that belonged to a previous query that had not been cleaned up.

Rejected

Details

Assignee

Reporter

Components

Affects versions

Priority

Created July 3, 2014 at 5:53 PM
Updated December 1, 2014 at 10:17 PM
Resolved December 1, 2014 at 10:17 PM