Skip to content

GH-1683 - Return persisted status from JpaEventPublicationAdapter#getStatus#1714

Open
BK202503 wants to merge 9 commits into
spring-projects:mainfrom
BK202503:GH-1683-fix-jpa-getstatus
Open

GH-1683 - Return persisted status from JpaEventPublicationAdapter#getStatus#1714
BK202503 wants to merge 9 commits into
spring-projects:mainfrom
BK202503:GH-1683-fix-jpa-getstatus

Conversation

@BK202503
Copy link
Copy Markdown

Fixes #1683.

Problem

JpaEventPublicationAdapter#getStatus() ignores the persisted status column and derives the value purely from completionDate:

public Status getStatus() {
    return publication.completionDate != null ? Status.COMPLETED : Status.PUBLISHED;
}

So a publication that was correctly marked FAILED (via markFailed) or RESUBMITTED (via markResubmitted) — both of which write the right value into the status column — still appears as PUBLISHED through getStatus(). The status persisted on the entity, the status reported by the API, and the status the repository's countByStatus queries operate on are out of sync.

Fix

Mirror what JdbcEventPublicationRepositoryV2's adapter already does (lines 768-775 of JdbcEventPublicationRepositoryV2.java): return the persisted status field when it is non-null, and fall back to the previous derivation for rows where the column may have been written before the field existed.

The fallback uses Status.PROCESSING rather than Status.PUBLISHED because:

  1. JpaEventPublication's constructor itself uses PROCESSING as its default when status is null and no completionDate is set, so this restores consistency.
  2. JdbcEventPublicationRepositoryV2 already uses PROCESSING for the same fallback.

Test

Added exposesPersistedStatusOnReload next to the existing markFailed tests. Without the fix it fails with expected: FAILED but was: PUBLISHED. The test clears the persistence context between the JPQL-based markFailed and the re-read so that we load a fresh entity from the database rather than the cached in-memory one — which is the production scenario (findIncompletePublications is called from a separate transaction).

Local result with the fix applied:

[INFO] Tests run: 58, Failures: 0, Errors: 0, Skipped: 0
[INFO] BUILD SUCCESS

Scope

  • Only spring-modulith-events-jpa (1 source change, 1 test added). The MongoDB / Neo4j adapters use different status accessors and the JDBC v2 adapter is already correct.
  • No public API changes.
  • No schema changes — the status column already exists on JpaEventPublication.

Looking forward to feedback. I had to sign the CLA on my first contribution — let me know if anything's missing on that side.

odrotbohm and others added 8 commits May 14, 2026 20:47
…rnalization.

To ensure proper ordering of messages externalized via the outbox, we now block the generic execution that returns a CompletableFuture.

Co-Authored-By: Roland Beisel <info@rolandbeisel.de>
Signed-off-by: SAY-5 <saiasish.cnp@gmail.com>
…ion for database-related slice test annotations.
…tionAdapter#getStatus

Currently the JPA adapter derives the status from `completionDate` alone,
returning either COMPLETED or PUBLISHED. As a result, publications that
were marked FAILED (or RESUBMITTED) by `markFailed` / `markResubmitted` —
both of which already write the correct value into the `status` column —
appear as PUBLISHED when read back through `getStatus()`.

Mirror the JdbcEventPublicationRepositoryV2 adapter: return the persisted
`status` when set, falling back to the previous derivation (with PROCESSING
as the default, matching the JPA entity's own constructor) when older rows
have a null status column.

The added integration test demonstrates the bug — without the fix it returns
PUBLISHED after `markFailed` — and clears the persistence context between
the JPQL update and the re-read so the test loads a fresh entity.

Signed-off-by: BK202503 <199436087+BK202503@users.noreply.github.com>
@BK202503 BK202503 force-pushed the GH-1683-fix-jpa-getstatus branch from 4647796 to 639eabd Compare June 3, 2026 14:45
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.

JpaEventPublicationAdapter returns incorrect status when getStatus() is called

2 participants