From 667b237c33784a5ebce072a0e656cd9333e25509 Mon Sep 17 00:00:00 2001 From: Marcel Date: Mon, 18 May 2026 19:04:22 +0200 Subject: [PATCH] docs(document): add WHY comments to @Transactional(readOnly=true) methods These annotations deviate from the project convention (read methods are normally unannotated). The comment explains that the session must stay open for callers to access lazy-loaded collections post-return, preventing future developers from removing the annotation as a cleanup. Co-Authored-By: Claude Sonnet 4.6 --- .../org/raddatz/familienarchiv/document/DocumentService.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/backend/src/main/java/org/raddatz/familienarchiv/document/DocumentService.java b/backend/src/main/java/org/raddatz/familienarchiv/document/DocumentService.java index 2b428b70..e4bd434d 100644 --- a/backend/src/main/java/org/raddatz/familienarchiv/document/DocumentService.java +++ b/backend/src/main/java/org/raddatz/familienarchiv/document/DocumentService.java @@ -636,7 +636,8 @@ public class DocumentService { return saved; } - // 0. Zuletzt aktive Dokumente (sortiert nach updatedAt DESC) + // @Transactional(readOnly=true) keeps the Hibernate session open so the + // lazy-loaded sender and tags on returned documents remain accessible to callers. @Transactional(readOnly = true) public List getRecentActivity(int size) { return documentRepository.findAll( @@ -845,6 +846,8 @@ public class DocumentService { documentRepository.save(doc); } + // @Transactional(readOnly=true) keeps the Hibernate session open so the + // lazy-loaded tags and receivers on the returned document remain accessible to callers. @Transactional(readOnly = true) public Document getDocumentById(UUID id) { Document doc = documentRepository.findById(id)