VSB-TUO/ORCID authority search fix#1259
Merged
milanmajchrak merged 3 commits intocustomer/vsb-tuofrom Feb 26, 2026
Merged
Conversation
…indexing Bundle.getBitstreams() creates a defensive copy (new ArrayList) which triggers lazy loading of the bitstreams collection. When the Hibernate session is already closed (e.g. during CLI database migration reindexing), this causes a LazyInitializationException. Wrap the call in try-catch to gracefully skip bitstream uncaching when the session is unavailable.
Bundle.getBitstreams() creates a defensive copy via new ArrayList<>(this.bitstreams) which iterates the Hibernate proxy and triggers lazy loading BEFORE Hibernate.isInitialized() can check the proxy state. All other getters (Item.getBundles, DSpaceObject.getHandles, etc.) return the raw Hibernate proxy, so isInitialized() works correctly for them. Guard with session.contains(bundle) instead: if the bundle is still managed by the session, lazy loading works normally; if detached (e.g. after session.clear() during batch processing), we skip - there is nothing to evict from a closed session.
There was a problem hiding this comment.
Pull request overview
Updates Hibernate session cache eviction behavior to avoid triggering lazy-loading of Bundle bitstreams when a Bundle may be detached, preventing LazyInitializationException during uncacheEntity().
Changes:
- Adjusts
HibernateDBConnection.uncacheEntity()logic forBundleto avoid callingBundle.getBitstreams()in scenarios where the entity is detached. - Adds detailed inline rationale explaining why
Bundle.getBitstreams()is unsafe to call as a lazy-init guard.
Comments suppressed due to low confidence (2)
dspace-api/src/main/java/org/dspace/core/HibernateDBConnection.java:314
getSession().contains(bundle)only checks whether the Bundle entity is managed; it does not indicate whether thebitstreamscollection is initialized. As a result, this branch will still force initialization viabundle.getBitstreams()whenever the bundle is in-session (potentially triggering extra DB reads), and it will skip uncaching bitstreams for detached bundles even when thebitstreamscollection is already initialized. With Hibernate 5.6 available in this repo, preferHibernate.isPropertyInitialized(bundle, "bitstreams")(or equivalent) to guard iteration without triggering lazy-loading, and keep behavior aligned with the surroundingHibernate.isInitialized(...)patterns (e.g. forItem.getBundles()).
if (getSession().contains(bundle)) {
for (Bitstream bitstream : Utils.emptyIfNull(bundle.getBitstreams())) {
uncacheEntity(bitstream);
}
}
dspace-api/src/main/java/org/dspace/core/HibernateDBConnection.java:314
- This change is addressing a LazyInitialization edge case in
uncacheEntity()for Bundles, but there is no test covering the Bundle/bitstreams eviction path. Please add/extend unit/integration tests (e.g. inHibernateDBConnectionTest) to verifyuncacheEntity(bundle)does not throw when the Bundle is detached andbitstreamsis uninitialized, and that it does not unexpectedly initialize the collection when it shouldn't.
if (getSession().contains(bundle)) {
for (Bitstream bitstream : Utils.emptyIfNull(bundle.getBitstreams())) {
uncacheEntity(bitstream);
}
}
WorkflowCurationIT.curationTest fails when CreateMissingIdentifiersIT runs first, because it pollutes the shared named plugin cache in LegacyPluginServiceImpl. Port upstream fix from DSpace#11907 (dspace-7_x backport): add clearNamedPluginClasses() call at test start to reset plugin state. See: DSpace#8533
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem description
Analysis
(Write here, if there is needed describe some specific problem. Erase it, when it is not needed.)
Problems
(Write here, if some unexpected problems occur during solving issues. Erase it, when it is not needed.)
Manual Testing (if applicable)
Copilot review