Skip to content

VSB-TUO/ORCID authority search fix#1259

Merged
milanmajchrak merged 3 commits intocustomer/vsb-tuofrom
vsb/orcid-authority-fix
Feb 26, 2026
Merged

VSB-TUO/ORCID authority search fix#1259
milanmajchrak merged 3 commits intocustomer/vsb-tuofrom
vsb/orcid-authority-fix

Conversation

@milanmajchrak
Copy link
Collaborator

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

  • Requested review from Copilot

…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.
Copilot AI review requested due to automatic review settings February 26, 2026 07:54
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 for Bundle to avoid calling Bundle.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 the bitstreams collection is initialized. As a result, this branch will still force initialization via bundle.getBitstreams() whenever the bundle is in-session (potentially triggering extra DB reads), and it will skip uncaching bitstreams for detached bundles even when the bitstreams collection is already initialized. With Hibernate 5.6 available in this repo, prefer Hibernate.isPropertyInitialized(bundle, "bitstreams") (or equivalent) to guard iteration without triggering lazy-loading, and keep behavior aligned with the surrounding Hibernate.isInitialized(...) patterns (e.g. for Item.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. in HibernateDBConnectionTest) to verify uncacheEntity(bundle) does not throw when the Bundle is detached and bitstreams is 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
@milanmajchrak milanmajchrak merged commit bf554cb into customer/vsb-tuo Feb 26, 2026
11 of 12 checks passed
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

Successfully merging this pull request may close these issues.

2 participants