Lots of discussion happened on the closed PR : https://github.com/hibernate/hibernate-orm/pull/1542 Essentially, I can understand the point of view here. This is counter-intuitive to what most developers would expect. They'd view the filter as associated/attached to the collection, whereas HIbernate strictly associates it with the Session. Once the Session is gone, the filters are gone. Again, I can see that as counter-intuitive. My concern is the performance. I won't get into a discussion about the correctness of allowing the initialization outside of the originating Session. We support that, and as such it should work properly. We just need to make sure it works in a performant manner. To that end, I think the bare minimum change in regards to the initial PR would be to conditionally copy the filters on to the AbstractPersistentCollection. For sure we should not copy them if SessionFactoryOptions#isInitializeLazyStateOutsideTransactionsEnabled is false. Ideally we'd limit copying them to just the AbstractPersistentCollection#prepareForPossibleLoadingOutsideTransaction process; but I am not sure that catches all cases. Just thinking in terms of isolating these fields that are needed only when "initialization outside of the originating Session" is enabled, I wonder if we could introduce an interface for the controlling initialization in those cases. |