fix: use merge() for in-session entities to prevent @PartitionKey NPE on re-attach - #160
Draft
r0goyal wants to merge 1 commit into
Draft
fix: use merge() for in-session entities to prevent @PartitionKey NPE on re-attach#160r0goyal wants to merge 1 commit into
r0goyal wants to merge 1 commit into
Conversation
|
…nly=false for update ops - Cherry-picked fix/skip-readonly-transaction-correct-paths (PR #158): wires skipReadOnlyTransaction correctly to single-query OpContexts only. - In MultiTenantRelationalDao and MultiTenantLookupDao inner Shard.update(): if the entity is already managed in the session, use session.merge() instead of evict+session.update(). Evicting a managed entity throws away its loadedState; re-attaching via update() leaves loadedState=null, which causes an NPE in Hibernate 6.2+ when @PartitionKey calls bindPartitionColumnValueBindings(). merge() on a managed entity copies state without destroying the session entry. - Change GetAndUpdate, SelectAndUpdate (MultiTenantRelationalDao) and GetAndUpdateByLookupKey (MultiTenantLookupDao) execute() calls from readOnly=true to readOnly=false. Update transactions were running in read-only sessions, which disabled dirty-checking snapshots and caused updates to be silently lost. merge() on a read-only managed entity is still skipped at flush, so readOnly=false is required alongside the merge() change. - Bump version to 2.1.12-HIBERNATE6-SNAPSHOT. Verified: all 720 kisht-core tests pass (0 failures, 0 errors). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
r0goyal
force-pushed
the
fix/partition-key-hibernate6
branch
from
August 12, 2026 15:05
3ae6101 to
54db778
Compare
|
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
MultiTenantRelationalDao and MultiTenantLookupDao inner
Shard.update()methods used anevict()+update()pattern to force a flush. When session.evict() removes an entity that was loaded in the same session,Hibernate discards its loadedState snapshot. On flush, Hibernate 6.2+
AbstractMutationCoordinator.bindPartitionColumnValueBindings()accessesloadedState[I]with no null check → NPE for any entity annotatedwith @PartitionKey.
Fix
In both DAOs, before falling back to evict+update, check if the entity is already managed:
merge() on a managed entity propagates the state without evicting, keeping loadedState intact for the partition column binding at flush.