Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FORCE_LAZY_LOADING can cause useless session if FetchMode is set to JOIN #128

Open
pip8786 opened this issue Apr 13, 2019 · 1 comment
Open

Comments

@pip8786
Copy link

pip8786 commented Apr 13, 2019

I have an ElementCollection on my object that is defaulting to lazy loading, but in my Criteria I've set the FetchMode to Join, which initializes the collection. While this causes the initialization of the collection to be identical to FetchType.Eager on the collection itself, it's marked at using lazy loading and therefore falls into the code linked here:

if (!Feature.FORCE_LAZY_LOADING.enabledIn(_features) && !coll.wasInitialized()) {
return null;
}
if (_sessionFactory != null) {
// 08-Feb-2017, tatu: and not closing this is not problematic... ?
Session session = openTemporarySessionForLoading(coll);
initializeCollection(coll, session);
}
return coll.getValue();

I think getting to this point is fine, but shouldn't it be checked that !coll.wasInitialized() on line 290, prior to opening a temporary session that will essentially do nothing since the collection is already initialized?

@pip8786
Copy link
Author

pip8786 commented Apr 13, 2019

Found another issue here. If I turn off FORCE_LAZY_LOADING for the module, it still opens the session since there is no check for the collection already being initialized before doing so. In other words, the FORCE_LAZY_LOADING feature doesn't actually matter in this case, the collection should be checked for wasInitialized before setting up a session and calling initialize on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant